Chasing 273, England collapsed from 100-0, with 19-year-old Mehedi Hasan taking 6-77 and Shakib al Hasan 4-49.
They had earlier dismissed the hosts for 296 after four dropped catches.
Bangladesh had only beaten Zimbabwe and a weakened West Indies team in 95 previous Tests, but the 108-run win means the series finished 1-1.
England needed their highest successful run chase in Asia and looked well set after a century opening partnership between Alastair Cook and Ben Duckett.
But they lost all 10 wickets in 22.5 overs in the final session as Bangladesh secured the biggest win in their history.
Duckett (56) scored his first Test half-century but was bowled by Mehedi with the first ball after tea, prompting the stunning collapse – the worst by a team who had been 100-0 in Test history.
Joe Root was out lbw in the following over to Shakib, before Gary Ballance and Moeen Ali were dismissed in the same Mehedi over shortly afterwards.
Cook made 59 but, despite successfully overturning one dismissal, the England captain was caught off Mehedi by Mominul Haque at silly point.
Shakib then dismissed Ben Stokes, Adil Rashid and Zafar Ansari in quick succession.
Fittingly, Mehedi took the final wicket of Steven Finn to finish with six in the innings, 12 in the match and 19 in the series.
Openers Cook and Duckett, who batted together for the first time in the first Test in Chittagong, had only managed a best partnership of 26 in their previous three innings.
Duckett, 22, impressed with an aggressive 56, hitting seven fours and a six, and played a number of reverse sweeps and pull shots.
Bangladesh bowled all four spinners in the session leading up to tea but they took no wickets in helpful conditions.
Cook had scored four, 12 and 14 in the series but also batted fluently in a period that seemed to swing the game in England’s favour.
England will rue their failure to take early wickets as Bangladesh added 116 runs in the morning session and Cook’s side dropped four catches.
Imrul Kayes scored 78 but was dropped at leg slip by Cook off the bowling of Ansari, and then by Root off Moeen in the first 10 overs of the day.
Both were difficult catches but Duckett dropped a simple chance at deep mid-wicket later in the session with Shakib the batsman to benefit.
Finn also put down a difficult diving chance, while England chose not to review the umpire’s decision on two occasions when replays showed the batsman would have been given out if they had done so.
Kayes’ innings and 41 from Shakib helped Bangladesh to 268-7 at lunch, but Stokes (3-52) and Rashid (4-52) helped England knock over the tail in 26 balls after lunch.