Williamson survived two stumpings and a leg-before decision before knocking an unbeaten 105, while Ish Sodhi was on one, with the tourists leading by two runs. Williamson's 25th Test century is his first in international cricket since he racked up 238, also against Pakistan, in Christchurch in January last year.
He built on a solid foundation laid down by openers Latham, who cracked 113 en route to his 13th Test century, and Devon Conway, who fell for 92. With the National Stadium pitch likely to take spin on the last two days, New Zealand will look to press home their advantage in the first Test of the two-match series, their first in Pakistan since 2002.
Williamson pushed fast bowler Mohammad Wasim for a sharp single to complete his hundred, a fifth against Pakistan. In all he has batted for 356 minutes, cracking 11 boundaries.
But Pakistan were left ruing missed chances as wicketkeeper Sarfaraz Ahmed fumbled two stumpings with Williamson on 15 and 21 -- spinner Nauman Ali the unlucky bowler on both occasions.
"I think they were chances but one of the deliveries was on the leg side and Sarfaraz did his best," said Nauman.
"This pitch is on the slow side so our effort will be to get the last four wickets early on day four and then set a good target of close to 200 -- which will be good on this pitch."
Williamson added a solid 90 for the fifth wicket with Tom Blundell, who fell to Wasim after scoring 47. Pakistan's spin duo of Nauman and Abrar Ahmed took two wickets in the post-lunch session, with Henry Nicholls falling for 22 and Daryl Mitchell scoring a robust 47-ball 42.
Ahmed, who has figures of 3-143, also had Michael Bracewell for five.
Williamson's DRS saves his day
Williamson, who also overturned a leg-before decision against him on 13, added 65 for the fourth wicket with Mitchell. Mitchell smashed seven boundaries and a six including four consecutive fours off Wasim after Pakistan took the second new ball at 272-3.
Earlier, resuming on 165 without loss, New Zealand were lifted by Latham's 13th hundred -- the most centuries by a New Zealand opener. Latham swept Ahmed for a single to reach three figures, eclipsing John Wright's 12 centuries as an opener for New Zealand.
He was finally dismissed for 113 after miscuing a reverse sweep and being caught at slip. Latham, who hit ten boundaries in his 288-minute knock, thinks New Zealand are in good shape to push for a win.
"The pitch has started to take more turn from the footmarks so obviously it's not going to get any easier for batting. Hopefully, from the position we are in, we can get as many ahead as possible and put Pakistan under pressure," Latham said.
Latham and Devon Conway put on 183 for the first wicket, beating the New Zealand record against Pakistan of 181 set by openers Mark Richardson and Matthew Bell at Hamilton in 2001.
Conway was trapped leg-before by Nauman for 92 after striking 14 boundaries in his fifth Test half-century. The Pakistan camp has been hit by viral flu with skipper Babar Azam not taking the field in the first session and Agha Salman missing for the entire day.