Sri Lanka restricted New Zealand to 276-8, in which Williamson's 59 was the highest score, and a blazing 65 from 45 balls by opener Danushka Gunathilaka ignited a run chase which Tillakaratne Dilshan strengthened with a masterly innings of 91.
Dilshan put on 111 for the second wicket with Lahiru Thirimanne before his innings ended when he was run out with Sri Lanka 202-2.
Thirimanne made an unbeaten 87 in a 68-run partnership with Dinesh Chandimal (27 not out) which closed out the win with 20 balls remaining.
"A very satisfying and much-needed victory for us," Sri Lanka captain Angelo Mathews said. "We gave ourselves a chance to stay alive in the series and going forward to the fourth ODI we still have a chance to square the series.
"I thought the bowlers were brilliant up front, given the task on a good track they kept them to a very chaseable target. And I thought all the batters batted brilliantly after the humiliating and embarrassing first couple of games."
Small changes on Thursday made a big difference to the dynamic of the series and Sri Lanka was just as commanding in winning the third match as New Zealand had in winning the first two.
The New Zealand bowlers couldn't contain Sri Lanka as they had done in the first two matches. Pacemen Tim Southee and Adam Milne returned after being rested earlier in the series and showed signs of rustiness, becoming cannon fodder for Gunathilaka and Dilshan, giving up 44 and 50 runs respectively from six over spells.
Williamson also returned to the New Zealand lineup after missing the first two matches of the series with a knee injury and was immediately installed as captain when Brendon McCullum was forced to withdraw with an injured back.
Williamson did something McCullum couldn't in winning the toss but that also worked against his team. Compelled to bowl first and chastened by the words of captain Angelo Mathews who described their previous performances in the series as "embarrassing and pathetic" Sri Lanka bowled well and fielded with enthusiasm to restrict New Zealand.
In the first match at Christchurch, Sri Lanka managed only 188 in ideal batting conditions and saw New Zealand surpass that total in 21 overs; in the second match Sri Lanka made only 117 and New Zealand reached that target in 8.2 overs.
But New Zealand's batsmen were less commanding Thursday on a pitch at Saxton Oval which was slower and lower than those on which the first two matches were played. Sri Lanka claimed wickets regularly, preventing the New Zealand innings from gaining momentum and leaving itself with an attainable total to keep the series alive.
"I think we certainly could have done it better," Williamson said. "I didn't think it was a bad total, probably par but we would have had to bowl well.
"If we had put together a couple of better partnerships that would have given us a bit more depth. But the way we came out in that first 10 overs was pretty poor but to Sri Lanka's credit they batted pretty well."
New Zealand looked likely to dominate again when Martin Guptill, who made 79 in the first match and 93 not out in the second, hurried to 30 from 28 balls in a 42-run opening partnership with Tom Latham.
But Guptill was out at that total and though Williamson arrived to steady the innings with his innings of 59, New Zealand was forced into a less aggressive approach than in Christchurch and the scoring never gained any real pace.
There were steady contributions throughout the New Zealand innings: Tom Latham made 42 and Mitchell Santner 38, Guptill and Doug Bracewell both made 30, before Tim Southee smashed 18 runs from the last four balls of the innings.
Brief Scores (For FULL SCORECARD click here)
New Zealand: 276 for 8 (Kane Williamson 59, Tom Latham 42, Mitchell Santner 38; Dushmantha Chameera 2/38, Jeffrey Vandersay 2/55, Nuwan Pradeep 2/55).
Sri Lanka: 277 for 2 (Tillakaratne Dilshan 91, Lahiru Thirimanne 87 not out, Danushka Gunathilaka 65; Mitchell McClenaghan 1/39).
Result: Sri Lanka beat New Zealand by 8 wickets.