The third seed appeared to be cruising to victory when she took the first set 6-2 and went a break up in the second.
But the 20-year-old American fought her way back to take the second set on a tie-break, then took advantage of some Sharapova errors in difficult conditions to seal her place in the third round, where she will face Jelena Jankovic or Ekaterina Makarova, who both won their first-round matches on Tuesday.
Second seed Victoria Azarenka avoided an upset as she held off American qualifier Vania King for a 6-1 7-6 (8/6) win in her second-round match.
There were mixed fortunes for two former world number ones, Caroline Wozniacki and Ana Ivanovic, in first-round play.
Tenth seed Wozniacki eased to a 6-1 6-1 win over China's Peng Shuai, but 15th seed Ivanovic was upset but France's Alize Cornet, who claimed a 2-6 7-6 (10/8) 6-4 victory.
Kirsten Flipkens, seeded 13th, was beaten 3-6 6-1 6-3 by Elena Vesnina of Russia.
Americans Varvara Lepchenko and Jamie Hampton beat Flavia Pennetta and Anastasia Pavlyuchenkova respectively, while Mona Barthel, Andrea Petkovic and Magdalena Rybarikova were also among the first-round winners.
In the men's draw, Roger Federer made a confident start as he saw off Germany's Philipp Kohlschreiber 6-3 7-6 (9/7) in the second round.
The Swiss fifth seed created chance after chance on the Kohlschreiber serve, but one break was enough to take the first set.
The German got an early break in the second but Federer fought back and took the match via a tie-break.
Third seed David Ferrer found live considerably tougher against Ryan Harrison.
The American wildcard went toe to toe with his illustrious Spanish opponent but was eventually out-battled 7-6 (7/5) 3-6 6-4.
In the day's other second-round matches Grigor Dimitrov eased past Brian Baker 6-3 6-2, while Julien Benneteau overcame Radek Stepanek in three sets.
Two seeds were ousted from the first round as Feliciano Lopez beat Kei Nishikori 6-4 7-6 (7/4) and Gilles Simon was forced to retire when 6-3 1-1 down to Canada's Vasek Pospisil.
There were no such troubles for Milos Raonic, Tommy Haas or Stanislas Wawrinka, who all progressed, while Mikhail Youzhny beat Ernests Gulbis in straight sets to deny the Latvian another shot at Wimbledon champion Andy Murray, who he beat in the Rogers Cup last week.
John Isner, Tommy Robredo, Jarkko Nieminen and Nikolay Davydenko were among the day's other winners.