O'Sullivan, who won the English Open earlier this year and is currently ranked 7th in the world, led by four frames to nil, with his highest break of 96 coming in the fourth frame, having scored 65, 70 and 86 in the previous three frames.
Williams looked set to fight back in the fifth after he compiled a 62 break and took the frame with 72 points, but the Rocket fired back, winning the sixth and final frame with 62.
Superb plant from O'Sullivan against Hawkins
O'Sullivan progresses to the semi-finals of the tournament for the first time since 2009, the year in which he also won, and will play either John Higgins.
Elsewhere Judd Trump saw off competition from Luca Brecel with a 5-0 victory - making it 23 unanswered frames in succession in Shanghai. He will play Jack Lisowski in the semi-finals.
Shanghai Masters Quarter-final Results
- John Higgins 5-1 Martin Gould
- Jack Lisowski 5-3 Kurt Maflin
- Judd Trump 5-0 Luca Brecel
- Ronnie O'Sullivan 5-1 Mark WIlliams
Fluke plant helps Hawkins against O'Sullivan
O'Sullivan edges astonishing tension-packed frame