The world No 2 from Russia was beaten 3-6 6-3 6-2 in two hours and eight minutes, losing nine of the last 12 games against the No 15 seed.
The 33-year-old Italian took advantage of some sloppy mistakes by Sharapova who served up 11 double faults during the contest.
Pennetta clinched a deserved victory on her second match point to set up a quarter-final with No 24 seed Sabine Lisicki.
Sharapova, who made 42 unforced errors, said: “Maybe I wasn’t playing my best tennis but I was competitive enough.
“I just wasn’t able to step up in the key moments.”
The German, who reached the Wimbledon final in 2013, edged out Caroline Garcia of France 6-4 6-4.
And world No 85 Lesia Tsurenko created a huge shock by beating the No 6 seed Eugenie Bouchard in a marathon battle that lasted just 11 minutes short of three hours.
The Ukrainian won 6-7 (5-7) 7-5 6-4, after recovering from 1-4 down in the final set which saw Bouchard drop her serve three times in a row.