Having bowled Sri Lanka out for 214, Bangladesh survived a mid-innings crisis that resulted in three run-outs before Jaker Ali hit the winning boundary off seamer Lahiru Kumara.
Bangladesh captain Mehidy followed his three-wicket haul with a top-score of 53 and was later adjudged the player of the match.
Nazmul Hossain made 40 and Jaker, who was forced to retire with cramps, returned to the crease and remained unbeaten on 31.
But Bangladesh hit back to grab three wickets in the space of 10 runs before skipper Charith Asalanka and Wanidu Hasaranga revived the innings with a 55-run stand for the sixth wicket.
Hasaranga fell for 30 while Asalanka was ninth out after top-scoring with 76 with the help of six boundaries and a six.
Off-spinner Mehidy finished with three for 28, while Mohammad Saifuddin and Abdul Haleem picked up two wickets each.
The home team's run-chase was hampered by the run-outs of their two main batsmen, Mehidy and Nazmul, before all-rounder Saifuddin also fell in similar fashion.
Needing 15 off the last two overs, Bangladesh took 11 runs in Fernando's penultimate over to ease the pressure before Jaker and Mehedi Rana carried their team past the victory target.
After the win Mehidy said the run-outs worried him, but was delighted his team won in the end.
"I am very proud of my team. I am sure the players have a very bright future ahead of them.
