Zimbabwe ended the day on 53-1, still trailing by 380 runs with nine wickets in hand, after left-arm spinner Taijul Islam trapped Sikandar Raza leg-before for 11.
Hamilton Masakadza was unbeaten on 15 and Brian Chari was on 21 when stumps were drawn.
Bangladesh lead the three-match series 1-0 after winning the first Test in Dhaka by three wickets.
The left-handed pair of Tamim and Shakib put Bangladesh on top with a fourth-wicket stand of 132 on a slow pitch.
Shakib made 137, his third Test century, with the help of 18 boundaries and two sixes.
Tamim scored a painstaking 109, his fifth Test hundred and the first in four years, with 10 fours.
When Tamim reached 100 off 312 balls, he recorded the slowest Test century by a Bangladeshi batsman – surpassing his elder brother Nafees Iqbal, who needed 309 deliveries to reach a hundred against the same opponents in 2005.
Bangladesh captain Mushfiqur Rahim played 31 consecutive dot balls before he was run out for 11, but Shakib broke free to reach his century with a straight drive off Tinashe Panyangara.
Tamim fell to part-timer Masakadza, before Malcolm Waller dismissed Shakib and Shuvagata Hom (15) to ease the pressure on Zimbabwe.
Taijul hit a quick-fire 32 off 44 balls to carry Bangladesh past the 400-run mark.
Tendai Chatara got rid of Taijul and Shahadat Hossain, before Natsai M'shangwe wrapped up the innings by claiming Jubair Hossain leg-before to earn his maiden Test wicket.
The third Test between the two lowest-ranked teams -- Zimbabwe at number nine and Bangladesh at 10 -- will be played in Chittagong from November 12-16.
The Tests will be followed by five one-day internationals.
Scorecard
Bangladesh 1st innings (overnight 193 for 3)
Tamim Iqbal c Ervine b Masakadza 109
Shamsur Rahman lbw b Chigumbura 2
Mominul Haque c and b Panyangara 35
Mohammad Mahmudullah lbw b Panyangara 56
Shakib Al Hasan b Waller 137
Mushfiqur Rahim run out 11
Shuvagata Hom c Chari b Waller 15
Taijul Islam c Masakadza b Chatara 32
Shahadat Hossain c M'shangwe b Chatara 18
Jubair Hossain lbw b M'shangwe 1
Rubel Hossain not out 0
Extras: (B-6, LB-6, W-2, NB-3) 17
Total: (all out, 158.5 overs) 433
Fall of wickets: 1-6, 2-78, 3-173, 4-305, 5-322, 6-376, 7-383, 8-426, 9-433.
Bowling: Panyangara 29-10-49-2, Chigumbura 22-5-60-1, Chatara 27-7-61-2, M'shangwe 40.5-7-127-1, Waller 23-4-65-2, Raza 11-2-31-0, Masakadza 6-1-28-1.
Zimbabwe 1st innings:
S Raza lbw b Taijul 11
B Chari not out 21
H Masakadza not out 15
Extras: (B-1, LB-5) 6
Total: (For one wkt; 19 overs) 53
Fall of wicket: 1-17.
Bowling: Shahadat 4-0-12-0, Taijul 8-2-21-1, Shakib 3-0-3-0, Jubair 3-1-11-0, Rubel 1-1-0-0.
Image: Shakib Al Hasan
Photograph: Phil Walter/Getty Images
Taijul's 8-wkt haul gives Bangladesh dramatic win over Zimbabwe
Test Rankings: Ashwin continues to top all-rounders list
Asian Games: Sri Lanka beat Afghanistan to win cricket gold
CLT20: Will IPL champs KKR repeat their super show against CSK?
Team India look serious contenders to defend their World Cup title