England had won all previous nine matches against their South Asian rivals but were all out for 164 in their second innings while chasing 273 for victory on the third day of the second and final test at the Shere Bangla National Stadium.
Off-spinner Mehedi took six wickets for the second time in the test as the hosts tied up the series at 1-1.
Bangladesh had come close to breaking England’s winning record in the first test at Chittagong but suffered a heartbreaking defeat by 22 runs.
England had looked in control as captain Alastair Cook and Ben Duckett took them to 100 without loss at tea, but the hosts produced a remarkable turnaround, taking all 10 of England’s second-innings wickets in the final session.
Mehedi, who took six first-innings wickets and seven in total on debut in Chittagong, once again proved to be England’s nemesis and picked up six for 77 on Sunday for a match haul of 12.
Duckett was dropped at slip on 12 and fell to the first delivery after tea for 56 with Mehedi breaching his defence after the batsman had completed his maiden test half-century.
Cook reviewed successfully on 44 to overturn an lbw decision off Mehedi but fell on 59 to a sharp catch at short point off the spinner, who turned 19 last week.
England still looked well-placed with Ben Stokes, who also had a successful review after being given out caught behind on 20 off Mehedi, and Chris Woakes at the crease.
But Shakib Al Hasan (4-49) picked up three wickets in four balls as England were shot out from 161-6 to 164 all out.
Mehedi was named both the man of the match and the series for his 19 wickets over the two tests.
MISSED CHANCES
Resuming the third day on 152 for three, the hosts were dismissed for 296 in the second session. England leg-spinner Adil Rashid took four for 52.
On a surface offering ample turn for the spinners, England made the chase more difficult with a string of missed chances.
Imrul Kayes, unbeaten overnight, and Shakib Al Hasan added 48 for the fourth wicket during a chance-filled partnership.
Kayes was dropped twice before off-spinner Moeen Ali finally trapped him leg before for 78.
Wicketkeeper Jonny Bairstow missed a stumping chance with Shakib on 16 before Duckett grassed a simple catch in the deep with the batsman on 23.
England also missed two review opportunities with replays showing the umpire’s decisions would have been overturned and Shakib continued to frustrate the tourists with a stroke-filled innings of 41.
Sabbir Rahman and Shuvagata Hom continued to attack the bowlers in a brisk stand of 30. A few heated words were exchanged between players from both sides during the partnership, prompting the umpires to intervene.
Rashid picked up the last two wickets in Bangladesh’s innings after lunch, while Stokes finished with three for 52.