SharaWildcard entrant Sharapova, a five-time grand-slam winner, squandered a 6-3 2-0 lead as Mladenovic clawed her way back into the game to win after two hours and 38 minutes.
Sharapova had not lost a set in the previous three matches of her comeback this week. Her defeat means she will finish outside the top 200 when the rankings are released on Monday, ruling out a qualifier spot for the French Open.
Sharapova, who was banned for using meldonium after testing positive at the 2016 Australian Open, has also received wildcards for forthcoming tournaments in Madrid and Rome.
The Russian was in complete control at the start, with her French opponent showing nerves, and a second double fault allowed Sharapova to race 4-1 clear.
She sealed the first set when Mladenovic sent a crosscourt backhand into the net after just 38 minutes.
The Russian, a three-time champion in Stuttgart, broke Mladenovic again at the start of the second set and looked to be cruising to victory as she took a 2-0 lead, attacking her opponent's second serve.
But despite conceding 11 double faults, Mladenovic improved her baseline game, chasing Sharapova with powerful ground strokes across the court.
She almost paid the price for her weak second serve -- a liability throughout the match -- but Mladenovic survived three break points to move into a 6-5 lead.
She took the set when Sharapova sent a forehand wide on Mladenovic's first break opportunity.
The pair traded blows early in the third before the Frenchwoman grabbed a break to go 4-2 up.
The 23-year-old world number 18 stood her ground when she found herself 0-40 in the next game, moving to 5-2, but a disastrous service game allowed the Russian briefly to come back before Mladenovic completed a memorable win to reach her first Stuttgart final with another break.
Read the original article on Eurosport: Sharapova defeated by Mladenovic in Stuttgart