The second-seeded Russian said she was still adjusting to changing weather conditions in Madrid and "the altitude as well" after winning the title in Stuttgart last weekend. Madrid is 2,180 feet above sea level.
"It was a tough match," Sharapova said. "I was really happy that I got that break back in the first set and was able to win in two sets."
Victoria Azarenka of Belarus also advanced, outlasting Anastasia Pavlyuchenkova of Russia 7-6 (8), 7-6 (3).
Azarenka, who finished runner-up in Madrid the past two years, is returning from an ankle injury and said it was good to get a tough test right away.
"I don't think I could have asked for a better match to start after a break," she said.
The third-ranked Azarenka broke to go up 4-3 in the first set before Pavlyuchenkova broke back. Azarenka then saved three set points at 6-3 down in the tiebreaker.
"When you don't play so much, you kind of lose that momentum," she said. "In the tiebreak, I just tried to find my game to find the solution to make things happen for me."
Laura Robson of Britain pulled off the first upset of the tournament, beating fourth-seeded Agnieszka Radwanska of Poland 6-3, 6-1 in a second-round match.
The 19-year-old Robson arrived in Spain coming off her sixth first-round loss of the year at the Portugal Open but was able to capitalize on her break points against last year's Wimbledon finalist.
In the men's event, 11th-seeded Nicolas Almagro of Spain advanced when Tobias Kamke of Germany retired injured after losing the first set 6-4.
Milos Raonic of Canada, American John Isner and Japan's Kei Nishikori were also first-round winners.
The top-seeded players in the men's draw, including Novak Djokovic, Rafael Nadal and Roger Federer, have a bye into the second round.