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.
"Nice (to get the century)," Williamson said. "When you're chasing a total you want to be positive and ... the partnership with Ross gave us a bit of momentum and relaxed the dressing room a little bit.
"A day five wicket, chasing anything can be tough, but to chase the (217) and do it well as a batting unit was all the more pleasing."
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 resume his innings, though returned to the ground after precautionary checks at Wellington Hospital.
"I am feeling much better. It could have been much worse," Mushfiqur said. "There is still a bit of pain there but hopefully I will get through."
His side eventually made 160, leaving New Zealand a victory target of 217 in 58 overs.
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.
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, however, effectively ended when Mushfiqur was taken to hospital.
"There is disappointment," Mushfiqur added. "We put in a good show for the first two, two-and-a-half days."
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.
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 Jan. 20 at Christchurch's Hagley Oval.