Ogilvie, 23, has spent the past two seasons on loan at the Gills having also had two spells with Stevenage.
He becomes Steve Evans' first signing since taking over as manager at the Priestfield Stadium earlier this week.
Ogilvie did not make a first-team appearance for Spurs having come through their academy but he has played more than 100 Football League games.
Gillingham have not disclosed whether they paid a fee for Ogilvie, whose Spurs contract was set to end this summer.
Need a VPN? Or seeking to switch? Then support Tribal Football by clicking here to sign up with our official partners NordVPN. Not only will you receive the best VPN experience, but also great discounts by signing up via Tribal Football. Thanks for your support!