Tamim followed up his 132 with an unbeaten 116 — his sixth ODI century — to steer Bangladesh to 240-3 off 38.1 overs in reply to Pakistan's 239-6.
Tamim hit 17 fours and one six in his run-a-ball innings, and shared a third-wicket partnership of 118 with Mushfiqur Rahim.
Rahim struck eight fours and a six in his 65 off 70 balls and was out with his side only 22 runs from victory.
Fast bowler Junaid Khan had given Pakistan an early breakthrough by dismissing Soumya Sarkar on 17 but Tamim kept piling up the runs, denying the visitors any chance of dominating the game.
Tamin added 78 with Mahmudullah (17) for the second wicket before the latter was dismissed by Saeed Ajmal (1-49) to give him his first international wicket since returning to the team after the ICC cleared his bowling action.
Bangladesh won the first match by 79 runs in its first victory over Pakistan after 16 years. It now leads the three-match series 2-0.
Earlier Saad Nasim and Wahab Riaz both struck half centuries to lift Pakistan to a fighting total from a precarious 77-5.
Nasim made 77 not out, hitting six fours and one six, while Riaz was undefeated on 51 with five fours and two sixes.
Playing in only his second ODI, Nasim enjoyed two significant partnerships. He first added 77 with Haris Sohail (44) to move his team to 154-6, then shared an unbeaten 85-run partnership with Riaz.
Shakib Al Hasan returned figures of 2-51 while Nasir Hossain, Rubel Hossain, Arafat Sunny and Mashrafe Bin Mortaza picked up one wicket apiece.
Bangladesh at first dominated after losing the toss, claiming two early wickets which included Mohammad Hafeez, the only experienced batsman in Pakistan's team, for a duck.
The Bangladeshi spinners played a vital role on the slow-paced wicket with Al Hasan, Nasir Hossain and Sunny sharing four of the first five wickets after Rubel Hossain made the breakthrough in his first ball, taking out Sarfraz Ahmed (7).