Chasing 187 for victory on Sunday, the home side slumped to 9-136 in the 40th over with India looking in command at the Shere Bangla National Stadium.
But Mehidy refused to throw in the towel, and combined with last man Mustafizur Rahman in a 51-run partnership, Bangladesh's highest for the 10th wicket, to secure a memorable victory with four overs to spare.
It was Bangladesh's second partnership of 50-plus runs for the 10th wicket but the first that's resulted in a victory.
"I am really excited that my innings helped the side achieve a victory from a position when few hoped for a victory," Mehidy said.
"I told Mustafizur that we should not give up hope. The strategy was to take it over by over and punish the bad balls. Happy to execute the plan perfectly. I'll keep this performance close to my heart always."
An upset looked on the cards after Bangladesh, having elected to field, bundled out India for 186 in 41.2 overs, with Shakib Al Hasan (5-36) the destroyer.
He wrecked India's top order, taking the wickets of Rohit Sharma (26) and Virat Kohli (nine) in the same over.
KL Rahul saved India's blushes with 73 off 70 balls before falling to Ebadot Hossain (4-47), who also claimed the important wicket of Shreyas Iyer (24).
Deepak Chahar gave India the perfect start by dismissing Najmul Hossain with the first delivery of the Bangladesh innings but skipper Litton Das (41) and Shakib (29) kept the hosts on course.
They suffered a mid-innings collapse but Mehidy, dropped by Rahul on 15, punished India for their sloppy fielding and general indiscipline in bowling which resulted in 17 extras.
In the final few overs, Mehidy showed grit and determination as India closed in on victory.
After surviving his scare, he launched a spectacular attack against Kuldeep, hitting him for two sixes in the space of three balls to transform the course of the match and put the pressure back on India.
India lost their momentum and Mehidy confirmed his side's victory, driving Chahar through cover for a single.
"They held their nerve in the end. If you look back how we bowled right from ball one — of course we would have loved to bowl better at the end — but we bowled pretty well for 40 overs and took wickets," said Sharma.
"We just didn't have enough runs. Another 25-30 runs would have helped. We were looking at 240-250 after the 25-over mark. When you keep losing wickets it is difficult. We need to learn and understand how to play on such wickets."
Mirpur will also host the second ODI of the three-match series on Wednesday.