© Getty Images
The former champion played an error-strewn first set, losing it without winning a single game in just 26 minutes.
The 19th seed fought back in the second, winning it by the same scoreline by which she had lost the first to send the match to a decider.
Both players struggled to hold their serve in the third set, with Williams breaking the Italian in the opening game, before Errani edged ahead.
The American got back in front and served for the match at 5-3, but a couple of long forehands kept her opponent in the tie, taking the set to a tie-break.
Williams showed her resilience again, coming back from 5-2 down in the breaker to draw level, but Errani hit back-to-back winners in a couple of long rallies to seal the match.
Errani will face Mirjana Lucic-Baroni in the fourth round after she stunned world number two Simona Halep.