Yan looked on course for an upset in Sheffield when he edged 10-8 ahead but three-time competition winner Williams hit an eye-catching 135 break on his way to levelling at 10-10 before pulling clear and ending his Chinese opponent's remarkable journey at the Crucible with a break of 78.
The 47-year-old 'Welsh Potting Machine' and former world number one said he was delighted to get over the line and book his place in the last four.
"It was a great match to be involved in. I was 6-2 in front and a lot of people think 'it's a great lead you should win' but it is nothing in this format. To make two breaks at the end under extreme pressure, what can I say, I am over the moon," Williams told reporters.
Williams has rolled back the years to return to top form this season, winning the British Open in August last year and reaching the quarter-finals of the Players Championship and Tour Championship.
He is into the last four for the seventh time in his career and will now take on either Judd Trump or Stuart Bingham in the semi-finals at the famous South Yorkshire venue.
The 2000, 2003 and 2018 winner will go level with John Higgins and Mark Selby if he wins the competition for the fourth time and Williams said he felt he had earned his place in the last four.
"I deserved that because a lot of matches that have been close this year have gone the other way, so I have got one," he said.
"I am playing as well as I have all season. I flagged last night and if it had carried on [then] there was no way I could have won."
Earlier today, the six-time World Snooker Championship.winner, Ronnie O'Sullivan, set up a semi-final clash against either four-time winner Higgins or Jack Lisowski after a 13-5 win over Stephen Maguire.