The seventh-seeded Russian made a slow start on Court Philippe Chatrier, falling behind 4-0 before finally winning a game. She then started to land her shots, and her serves, with more consistency and won nine of the last 10 games.
Muguruza, who was playing in a Grand Slam quarterfinal for the first time in her career, eliminated defending champion Serena Williams in the second round.
Sharapova lost in the semifinals at Roland Garros in 2011, then won the title a year later to complete a career Grand Slam. She lost in last year's final to Williams.
"It was so tough losing in the final last year, being the defending champion," Sharapova said. "This year, to come back, I have the extra motivation to go further, and to be back on (this) stage is a really nice feeling."
Sharapova will face Eugenie Bouchard in the semifinals. The 18th-seeded Canadian beat Carla Suarez Navarro of Spain 7-6 (4), 2-6, 7-5.
Sharapova opened her match with a double fault, the first of eight in the match. And she lost 15 of the first 20 points.
But even though Sharapova held in the fifth game, she was broken again, this time at love, to lose the first set.
Things changed rather quickly in the second set. At 1-1, Sharapova finally broke, with some help from Muguruza.
The unseeded Spaniard, ranked 35th in the world, double-faulted twice in a row to give Sharapova her second break point of the match. The tall Russian converted when Muguruza sent a backhand long.
Although Sharapova was broken again in the set, again with a double fault, she started to hold serve more easily while giving Muguruza more trouble while receiving.
By the time the third set started, Sharapova was moving Muguruza all over the court, landing her forehands and backhands easily.
The only hiccup came in the fourth game, when Muguruza had five break points but couldn't convert any of them.
"That was one of the most important games," Sharapova said. "After I won that game, I certainly gained more confidence."
Like Sharapova, Bouchard also struggled early in her match, trailing Suarez Navarro 5-2 before taking the first set. In the third, Bouchard fell behind 4-1, but won 12 straight points to get to 4-4.
In the final game of the match, the chair umpire twice called for points to be replayed. Bouchard won both replays, with the second one giving her match point.
On the third match point, Suarez Navarro hit a backhand into the net
"I am going to rest a lot now. I'm quite tired, but it's OK," Bouchard said. "I'm really excited to be in Paris for two more days and to play in the semifinals at Roland Garros."
The Associated Press contributed to this report.