The New Zealand skipper scored 104 not out, reaching his century from 89 balls, and combined with Ross Taylor (60) in a 163-run partnership as the hosts reached 217 for three with 17.2 overs remaining in the match.
Henry Nicholls was on four when Williamson hit the winning run, a single out to deep mid-wicket.
However, the joy of victory was tempered by an incident earlier in the day when Bangladesh captain Mushfiqur Rahim suffered a sickening blow to the head from a Tim Southee bouncer and was taken to hospital by ambulance.
Result a possibility after Bangladesh rattled by triple blow
Mushfiqur, who scored 159 in the first innings, had been battling to save his side after they had slumped to 96-5 having taken a 56-run lead into their second innings. He did not return and his side eventually made 160 for nine, leaving New Zealand a victory target of 217 in 58 overs.
Bangladesh had scored 595-8 declared in their first innings and looked to be in charge of the game from early on the second day.
A draw, however, had been the most likely result until late on the fourth day when the hosts, who replied with 539, took three late wickets to give themselves a sniff of the unlikely victory. They capitalised early on the fifth day, dismissing first innings double centurion Shakib Al Hasan for a five-ball duck.
Latham’s ton keeps New Zealand afloat against Bangladesh
Once Shakib fell, the onus rested with Mushfiqur and Sabbir Rahman to bat out the rest of the day and stave off a potential morale-sapping defeat. Their resistance effectively ended when Mushfiqur was taken to hospital. Sabbir threw away his wicket on 50 and despite a hobbling Imrul Kayes returning after retiring hurt on 24 on Sunday, New Zealand ran through the tail.
While Bangladesh took early wickets to reduce New Zealand to 39-2, Williamson and Taylor took control with the captain hitting three successive boundaries in the final over before tea from Taskin Ahmed to signal his intentions.
Double-centurion Shakib helps Bangladesh pile up mammoth total
The hosts began the final session on 91-2, needing a further 126 runs in 38 overs to clinch victory.
Williamson then took the game totally away from Bangladesh with a superbly controlled attacking innings after tea, racing through to his 15th Test century after he lost Taylor with victory in sight. The second game of the two-match series starts on January 20 at Christchurch's Hagley Oval.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ