Sharapova was pushed all the way by third seeded German star Angelique Kerber before winning 6-3 2-6 7-5.
Kerber was on the back foot for most of the match but consistently grabbed her chances better than the Russian, saving five of the 10 break points against her.
Sharapova's serving and returning under pressure in the final set proved to be key, however. Kerber had her chances to win and broke Sharapova twice, but the Russian hit back with breaks of her own before breaking once more and clinching the match.
Li, by contrast, faced few problems as she dismissed American qualifier Bethanie Mattek-Sands 6-4 6-3, giving the world number five hopes of a second title of the year.
Lourdes Dominguez Lino will face Francesca Schiavone in the final of WTA Marrakech after both came through their semi-final matches.
Sixth seed Schiavone fought through a tough opening set against South Africa's Chanelle Scheepers, but then found her range and cruised through the second set to win 7-6(4) 6-1.
Dominguez, meanwhile, looked in trouble after Luxembourg's world number 91 Mandy Minella stormed through the opening set.
But the tables were then turned in extraordinary style, with the Spaniard blitzing her opponent in the next two sets to run out a 2-6 6-0 6-1 winner.
WTA Stuttgart semi-finals
2-Li Na (China) beat Bethanie Mattek-Sands (U.S.) 6-4 6-3
1-Maria Sharapova (Russia) beat 3-Angelique Kerber (Germany) 6-3 2-6 7-5
WTA Marrakech semi-finals
Lourdes Dominguez Lino (Spain) beat Mandy Minella (Luxembourg) 2-6 6-0 6-1
6-Francesca Schiavone (Italy) beat Chanelle Scheepers (South Africa) 7-6(4) 6-1
- Sports & Recreation
- Angelique Kerber
- Francesca Schiavone
- Lourdes Dominguez Lino