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.''
Djokovic beat eighth-seeded Milos Raonic of Canada 7-5, 7-6 (5), 6-4 to reach the semifinals at Roland Garros for the sixth time. He has only played in one final, however, losing to Rafael Nadal in 2012.
Gulbis is competing at his 27th major tournament, but this is only the third time he has advanced past the third round. He reached the quarterfinals at the French Open in 2008, but lost to Djokovic.
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.''