Sharapova, the defending champion, needed more than three hours to overcome Lucie Safarova a day earlier. This one was an hour shorter but perhaps just as intense.
"It was hard to get my body going, I need some time to warm up a little," Sharapova said. "Another tough one."
Sharapova used this indoor clay-court tournament last year to warm up for the French Open, where she won the title.
Against Ivanovic, another former No. 1 and the 2008 French Open champion, Sharapova squandered a 4-1 lead in the third set before breaking serve again and serving out the match on her second match point.
Sharapova will next play third-seeded Angelique Kleber, who defeated Yaroslava Shvedova of Kazakhstan 6-3, 7-6 (2) to reach her third semi-final of the season.
Germany's No. 1 player is looking for her first title of the year after finishing runner-up in Monterrey. She made the last four in Stuttgart for the first time.
Shvedova trailed 4-1 before breaking back. But she dropped her serve again with two errors from the baseline. The two traded breaks in the first three games of the second before Kerber opened a 3-1 lead, only to see Shvedova pull level at 3-3. Kerber raced to a decisive 5-1 lead in the tiebreaker.
"I played my game and I was aggressive," Kerber said.