Bangladesh were 555 for six when the match concluded after a rain-disrupted final day.
The hosts, who trailed by 296 runs after Pakistan's mammoth first innings 628, will take huge confidence into the second test in Dhaka next week after rescuing a draw from what had looked like an almost hopeless position just a day earlier.
Tamim's 206 was the highest score by a Bangladeshi batsman in test cricket while his stand with Imrul was the first triple century partnership for the country in the longest form of the game.
The pair resumed on 273, trailing the visitors by 23 runs, and added 39 more runs before the stand was finally broken when Imrul holed out in the deep off Zulfiqar Babar, one of seven bowlers Pakistan used as they tried to force a result.
Tamim retained the aggression that had brought him such success on Friday and brought up his double century in some style, marching down the wicket and smashing Junaid Khan high and straight for his seventh six.
Pakistan finally got their man when Mohammad Hafeez, who also scored a double century in Pakistan's innings, beat Tamim with spin and Sarfraz Ahmed stumped him.
In addition to the seven sixes, Tamim hit 17 fours in the 278-ball, 448-minute knock.
Bangladesh's lead was now in triple figures and Shakib Al Hasan pitched in with an innings of 76 not out to steer the home side safely towards stumps.
The previous best test innings by a Bangladeshi batsman was 200, which Mushfiqur Rahim scored against Sri Lanka in Galle in 2013.
The previous highest stand for Bangladesh was the 267 for the fifth wicket between Mohammad Ashraful and Mushfiqur against Sri Lanka at Galle in 2013.

Latest News from Sports News Desk