O’Sullivan started the day's first 6-2 down to the former World Champion, and he looked to be in even more trouble when he missed frame ball to let Williams scrape his way to a 62-55 win to go five frames ahead.
A century break of 105 from O’Sullivan kicked off three consecutive frame wins for the Englishman, though Williams hit back with a 64-27 to interrupt his opponent's daring comeback.
- Judd Trump's World Championship reign ended by Kyren Wilson
- Neil Robertson: Mark Selby back to his world title-winning tactical best
- Mark Selby emerges as World Championship favourite after overcoming Neil Robertson
The Welshman saw his opponent win two more by similar margins, 24-76 then 25-74 leaving the second session scores at 8-6 with two frames remaining. O’Sullivan was closing in on yet another famous comeback. Williams for him may have represented what he considered his first serious test, given his admonishment of the younger players attempting to supplant him. To reassert his superiority over his younger peers, a break of 112 took him within one frame of parity.
In the last frame of the session, O’Sullivan took an early lead and a break of 54 was enough to lead Williams to concede the frame when needing snookers at 74-20. It marked the end of a second session that left O'Sullivan with at least an equal chance of reaching the semi-finals after looking close to elimination.
Ronnie O'Sullivan notches fourth ton to keep things level with Mark Williams
Williams took the first frame to go back ahead with the evening session's open, but O'Sullivan scrapped back to take the second. With the match at 9-9, Williams held his nerve for a 75-52 win to show he would not be psychologically cowed by his rival.
Ronnie O'Sullivan hits fifth century against Mark Williams with another brilliant clearance
That didn't matter to O'Sullivan. The next three frames saw him pull out breaks of 104, 61, 65 and 133 to go 12-10 ahead, one frame from victory.
Incredible sportsmanship! Mark Williams owns up to foul that referee missed
Then followed one of the longest frames of the game. With the pressure building, both missed chances they would otherwise have made in less stressful times. That pressure reared its head once again when O'Sullivan missed a routine blue, allowing Williams to tie the game and force the pair onto a deciding black. Williams was the first to crack and leave a black on, allowing O'Sullivan to take a famous victory.
After the match, O'Sullivan played down his efforts to come back, decrying his form.
"I was just pleased I made a game of it in the end. I was just scared that maybe I might not be able to make an impact on it, get beat 13-2, 13-3, a good mauling.
"On the practice table this morning I thought I've got to find something that will allow me to score because I wasn't cueing well. So I thought anything over three feet from the white, the table looked 40 feet long.
"But in the balls I was able to manufacture stuff, it was like a golfer couldn't find the fairway but in the greens... I played snooker like Seve Ballesteros.
"If I can find a cue action, I fancy winning tournaments. I think Mark [Williams] will think he lost that one really.
"I think Mark Selby is a certainty - I've got no game."
In the other game of the eveing, Anthony McGill looked poised for a straightforward win when he reached 12-8, a frame away from the semi-finals.
The obdurate Kurt Maflin refused to give in to what looked to be inevitable defeat and fought back to 12-10 to keep his hopes alive and his opponent just short of the win, but he could not hold back the tide in the final frame when he managed to claim his victory at last.
Ronnie O'Sullivan finishes off Mark Williams on re-spotted black