The five-time Grand Slam champion, who turned 31 last week, looked to be in control as she made just two unforced errors in winning the opening set.
But Garcia, who had never beaten the Russian in four previous meetings -- they last played in Madrid three years ago -- rallied in the second set as she came from 4-2 down and and levelled the contest in a tie-break.
The 41st-ranked Sharapova returned to tennis in Stuttgart exactly a year ago after finishing a 15-month doping ban for meldonium and reached the semi-finals.
She claimed an early break in the third set, but lost it in the third game as Garcia tightened the screw on the crowd favourite.
Sharapova was broken to trail 4-5 and put her opponent under momentary pressure at 0-30 as Garcia tried to serve out the win.
But the world number seven succeeded on her second match point as Sharapova struck a return wide to exit after two and three-quarter hours of battle on the indoor clay court.
Sharapova said her game might have been compromised by weeks of forearm injury recovery after last playing in Indian Wells six weeks ago.
"Overall I didn't react as well as I could against a server like her, she got lot of free points," Sharapova said.
"I didn't get enough balls back. We were both playing fast, and aggressive.
"I need to be smarter in the winning position."
Garcia will next take on Ukrainian qualifier Marta Kostyuk who scored a 6-4, 6-1 defeat of Antonia Lottner.
The youngster, who doesn't turn 16 until just before the start of Wimbledon, was joined in round two by Czech fifth seed Karolina Pliskova, who beat Dutchwoman Kiki Bertens 6-2, 6-2.
Kostyuk made a breakthrough with a surprise third-round showing at the Australian Open as a qualifier, finally losing to compatriot Elina Svitolina. World number 158 Kostyuk has since claimed a second-tier title in Burnie, Australia and reached a final in Zhuhai, China in March.
Her defeat of Lottner, ranked 155th, took just under 90 minutes, with the teenager breaking four times while losing serve only once.
Pliskova, who has been on site for a week training, is playing Stuttgart for the third consecutive year, after losing to eventual champion Laura Siegemund in the 2017 quarter-finals.
"I felt the best today and for sure it was not her best match but that was not much to do with me," Pliskova said.
"The serve was good and I got a lot of free points, my shots were working -- there was no problem from my side today." The Czech dominated Bertens, with the winner firing six aces and breaking four times.
Reigning champion Laura Siegemund beat Barbora Strycova 6-4, 6-3, but Marketa Vondrousova did get one over the Germans for the Czechs with a 6-2, 6-2 victory over Julia Goerges.
(This story has not been edited by Business Standard staff and is auto-generated from a syndicated feed.)