Williamson, who stepped down from the captaincy in his team's first test tour to Pakistan in 20 years, capitalized on two missed stumpings to hit an unbeaten 105 as the Black Caps reached 440-6 at stumps on the third day, a lead of two runs.
Tom Latham also made his 13th test century, becoming the first New Zealand opener to achieve the feat, and Devon Conway hit 92 as the visitors dominated the spinners on a slow turning wicket.
Mystery spinner Abrar Ahmed picked up 3-143 and left-arm slow bowler Nauman Ali took 2-137 but neither could wrestle control away from the batters.
Wicketkeeper Sarfaraz Ahmed, making a test comeback after four years, fumbled stumping opportunities when Williamson was on 15 and 21, while the former skipper also overturned an lbw ruling against Abrar through a television referral.
It was Williamson's first international century since his 238 against Pakistan in Hamilton in January 2021.
Tom Blundell (47) and Daryl Mitchell (42) played useful knocks and shared half-century stands with Williamson against some scrappy Pakistan fielding.
Blundell was dropped low down by Imam-ul-Haq at short mid-wicket before paceman Mohammad Wasim had him lbw late in the day.
Mitchell, who scored three centuries and two half-centuries in the three-test series against England in June, smashed four successive boundaries off Wasim after Pakistan took the second new ball.
Abrar removed Mitchell and Latham to reverse sweeps as the ball ballooned to close-in fielders after hitting their gloves.
Captain Babar Azam was among at least three Pakistan players hit by a virus and didn't take the field at the start. He stayed off until half an hour after lunch.
Salman Agha, who made a maiden test hundred in Pakistan's first innings 438, is unwell and hasn't fielded.
There was confusion when substitute fielder Mohammad Rizwan led the team for a while. However, team management had named Sarfaraz as the designated stand-in skipper and he eventually took charge because substitute fielders can't captain a side.
Latham raised his 100 with a single off Abrar before he fell for 113.
Resuming on 165-0, Latham and Conway stretched their opening stand to a record 183 before Nauman struck in his first over.
Conway had added 10 to his overnight 82 but was out lbw to a Nauman delivery, which spun sharply from the rough. Sarfaraz successfully overturned umpire Aleem Dar's not-out decision through a television referral.
The opening stand bettered New Zealand's previous first-wicket record against Pakistan when Mark Richardson and Matthew Bell shared a 181-run partnership in Hamilton in 2001.
New Zealand is on its first test tour to Pakistan since 2002 and Karachi will also host the second match next week after Multan was ruled out because of weather concerns. The two-test series will be followed by three ODIs, also in Karachi.