The tourists reached 231-4 by lunch on the third day, trailing Bangladesh by just 51 runs in the first innings with six wickets in hand.
All-rounder Anderson, playing only his second Test, took the lead in New Zealand's batting charge, scoring an unbeaten 75 alongside Williamson (56 not out) at the interval.
The pair stood firm after Shakib Al Hasan had raised the hosts' hopes by removing star batsman Ross Taylor for his fourth wicket in the innings.
Former skipper Taylor smacked five boundaries in his innings of 53 after New Zealand lost their openers cheaply on the rain-hit second day.
More From This Section
The Black Caps resumed the day's play on 107-3 and batted cautiously until Anderson and Williamson opened up to put the pressure back on the bowlers.
Anderson, 23, gloved the second ball he faced but it dropped inches short of wicketkeeper Mushfiqur Rahim.
His fluent batting allowed Williamson to anchor the innings and take New Zealand to a position from which they can now eye a first-innings lead.