The fourth seed was a set and a break down but recovered to win in two hours and eight minutes.
The 23-year-old will now play Yulia Putintseva, seeded 27.
The women's draw is wide open, especially after world number one Angelique Kerber and British hope Johanna Konta went out in round one.
"I was expecting this kind of match because I played her recently, and I saw her a little bit in the few tournaments before," Muguruza said of Kontaveit.
"She was just playing good, a lot of confidence. I knew it was going to be a battle out there."
Watched by sister Serena - who will not play again this season because of her pregnancy - Venus Williams easily beat Kurumi Nara 6-3 6-1 to move into round three for the first time in five years.
At 36 she is the oldest woman to reach the third round at the French Open since Billie Jean King in 1982.
Slovak Dominika Cibulkova suffered a shock defeat by Tunisia's world number 114 Ons Jabeur to become the third top-10 seed in the women's draw to be knocked out. The sixth seed lost 6-4 6-3.
Petra Kvitova's return to action came to an end in the second round as the Czech lost 7-6 (7-5) 7-6 (7-5) to American Bethanie Mattek-Sands.
Caroline Wozniacki, the Danish 12th seed, produced an impressive performance to beat Canadian Francoise Abanda 6-0 6-0 in 52 minutes.
French 13th seed Kristina Mladenovic reached the third round with a comfortable 6-2 6-3 win against Sara Errani of Italy.
In the men's draw, another home favourite, 12th seed Jo-Wilfried Tsonga, was given only the briefest of reprieves as he lost 7-5 6-4 6-7 (6-8) 6-4 to Argentine Renzo Olivo.
The match was postponed from Tuesday because of bad light and Olivo needed only one game to turn his overnight advantage into victory. He will now play Briton Kyle Edmund in the second round.
Austrian sixth seed Dominic Thiem was broken just once in a 7-5 6-1 6-3 win over Italian Simone Bolelli.
Bulgaria's 11th seed Grigor Dimitrov is also through after beating Spain's Tommy Robredo 6-3 6-4 7-5.
Defending French Open champion Garbine Muguruza survived a scare to beat world number 53 Anett Kontaveit 6-7 (4-7) 6-4 6-2 and reach the third round.