Sharapova won her first tournament of the year and clinched the 30th title of her career. She is now undefeated in 13 consecutive matches on the indoor clay in Stuttgart.
Ivanovic wasted a 3-1 lead in the second set as Sharapova raised her game to stay in the high-quality match between two former top-ranked players and French Open champions. Ivanovic was seeking her third title of the year.
''I just tried to hang in there,'' Sharapova said. ''For the first half of the match I thought it might not be my day today, but somehow I turned it around.''
Ivanovic got off to a flying a start and won the first five games of the match before Sharapova started fighting back.
Ivanovic wasted a set point and could not serve out the set at her first attempt. She gifted Sharapova another game with a double-fault but finally pulled together to win the first set.
Sharapova had trouble reading Ivanovic's varied game and change of pace. But she held on as Ivanovic began to lose her focus.
''From the first moment it was always a close match,'' Ivanovic said. ''It was always a few close balls to decide each game, and it went on the whole match. In the second set she definitely went for those big shots, though, and she made some amazing points.
''She's just a great player, and that's what happens when you play against great players in big matches like this. You need to use your opportunities.''
Sharapova returned late last year after missing four months following shoulder surgery.
''It was a very tough year for me,'' she said.
Stuttgart is the only tournament Sharapova has won three times.