A tense start to the later match at the Crucible was littered with mistakes and it was a missed routine black by Williams in the eighth frame that enabled Trump to establish a healthy overnight advantage.
The world number one produced his worst session of the tournament so far but finished strongly, even if at times he rode his luck against his 50-year-old opponent from Wales.
Three-time world champion Williams had drawn level at 2-2 at the interval after producing a break of 116 and the roller-coaster play continued with multiple mistakes as the score moved to 3-3.
Trump took a hard-fought seventh frame and when Williams missed an easy black in the eighth, the Englishman pounced to compile a break of 109 that propelled him into a two-frame lead.
Earlier, O'Sullivan and first-time semi-finalist Zhao shared the spoils in a gripping opening session, tying 4-4.
O'Sullivan's pedigree and experience on the big stage did not deter Zhao, who took a 2-0 lead and then finished impressively with a break of 86 to leave things all-square after the initial leg of their best-of-33 contest.
O'Sullivan won three frames in a row and at one stage stopped his opponent registering a point for almost 34 minutes.
Zhao, who is playing as an amateur as he continues his comeback from a 20-month ban for involvement in a betting scandal, settled quickly into his work as he picked up the first two frames with minimal fuss.
O'Sullivan wrestled back the momentum to lead 3-2 before Zhao drew level again.
Both players saved their best for last, with O'Sullivan regaining the upper hand with a break of 82 before Zhao hit back with 86.