Sharapova, seeded third, struggled in becoming the first big casualty of this year's championship, losing 6-3 3-6 6-4 in two and a half hours.
The Italian has reached the quarter-finals at Flushing Meadows twice before but pulled off one of the biggest wins of her career in a see-sawing match on the Arthur Ashe Stadium center court.
Pennetta, seeded 26th, raced to a 4-0 lead en route to winning the opening set. But Sharapova, who made 60 unforced errors and served 12 double faults, won the second back then recovered from 4-1 down to square the final set at 4-4.
Pennetta regained her composure to hold her serve to lead 5-4 then broke the Russian again to seal victory and advance to a fourth round clash with China's Peng Shuai.
(Editing by Steve Ginsburg)