New Zealand was 142-5 at stumps, chasing 189 to complete a sweep of the two-test series.
The Sri Lanka team will believe it is still in with a chance, particularly after a day on which 16 wickets fell and the upper hand in the match passed from one team to the other.
New Zealand's first innings was quickly ended in the morning, bowled out for 237 in reply to Sri Lanka's 292 to concede a 55-run first innings lead.
Sri Lanka then reached 71-0 in its second innings, seemingly on course for victory.
But the innings unraveled dramatically between lunch and tea as the tourists lost all 10 wickets for 62 runs in less than 90 minutes to be all out for 133 and to leave New Zealand chasing a moderate target.
New Zealand then stumbled to 11-2 in the face of the hostile pace bowling of Dushmantha Chameera, who took 5-47 in the first innings, to again rally Sri Lanka's spirits. Chameera had figures of 4-45 in the second innings, and stands a strong chance of taking 10 wickets in what is only his third test.
Williamson continued his impressive recent form as he put on 67 with Ross Taylor (35) for the third wicket and 52 with Brendon McCullum (18) to edge towards victory.
However, there is only the tail-enders to follow the current pairing of Williamson and B.J. Watling, so an early wicket Monday would significantly boost Sri Lanka's hopes.
Run-scoring was never easy Sunday and Williamson was one of few to bat with sufficient application to make a significant score. Sri Lanka's batsmen were repeat offenders in hitting at short balls they could have left.
Tim Southee took 4-26 and Neil Wagner 3-40 capitalized on that rashness as Sri Lanka's second innings fell apart.
Doug Bracewell initiated the collapse, removing Dimuth Karunarate (27) to end his 71-run opening stand with Mendis, then Udara Jayasundera without scoring, also at 71.
Southee then raced through the middle order, removing opener Kusal Mendis for 46 — which equaled his highest score in tests — and adding the wickets of Angelo Mathews for 2 and Rangana Herath (0) before dismissing Nuwan Pradeep to end an innings which lasted only three hours and 36.3 overs.
"That's what you call test cricket," Wagner said. "It's a test of your skills and temperament in the heat of battle and in a difficult environment.
"The guys are still pretty confident of getting the runs. We'll go to bed tonight knowing there's still a lot of work to do and we'll come back tomorrow to get those runs, confident that we can get them."
Sri Lanka produced another twist in the day's play when it rapidly dismissed openers Tom Latham for 4 and Martin Guptill for 1.
Williamson showed a typically cool head to guide New Zealand within sight of a victory which would preserve its unbeaten record in home tests which stretches back to March, 2012. Balanced against that, New Zealand has lost four of its past five tests in Hamilton.
Taylor batted well before losing his wicket to a rash shot which produced a catch on the boundary. McCullum never looked comfortable and hasn't throughout the series. He scratched for runs and was out to a loose shot and a catch in the covers.
Sri Lanka 1st innings 292 (Angelo Mathews 77, Milinda Siriwardana 62; Tim Southee 3-63).
New Zealand 1st innings: 237 (Martin Guptill 50; Dushmantha Chameera 5-47).
Sri Lanka 2nd innings: 133 (Kusal Mendis 46; Tim Southee 4-26, Neil Wagner 3-40).
New Zealand 2nd innings: 142 for 5 (Kane Williamson 78 not out; Dushmantha Chameera 4-45).