Bangladesh lost to Hong Kong for the first time on Thursday but qualified for the World Twenty20 main draw on run rate.
Bangladesh, unbeaten in the group stage and expected to romp past win-less Hong Kong but were dismissed for 108 in 16.3 overs. Hong Kong then had to reach the winning target within 14 overs to ruin the party for the tournament host and help Nepal advance instead.
But Hong Kong also struggled to score and didn't earn its maiden World T20 victory until the last over, with two wickets and two balls left, Haseeb Amazad hitting the historic winning runs with a six over extra cover off Abdur Razzak.
Bangladesh moved into Group 2 of the Super 10 with India, Pakistan, Australia and the West Indies. The host's first match is against the West Indies on Tuesday.
For Hong Kong, spinner Nadeem Ahmed claimed 4-21, legspinner Nizakat Khan had figures of 3-19, and medium pacer Tanwir Afzal took 2-24, starting the rout of Bangladesh with both wickets in the first over.
Shakib Al Hasan top-scored with 34, his dismissal sparking Bangladesh's collapse from 85-3.
Shakib then boosted his side with his left-arm spin, taking 3-9 in four overs to slow down Hong Kong and dash Nepal's hopes.
Opener Irfan Ahmed put Bangladesh's aspirations in jeopardy with three sixes and three boundaries but Shakib produce a gem that spun viciously to trap Ahmed lbw, out for 34 off 28 balls.
Mahmudullah joined Shakib in frustrating Hong Kong further but Munir Dar rose to the occasion. He ripped 36 off 28, including three fours and one six, although Bangladesh had already qualified by then.
Razzak dismissed Dar, then Sabbir Rahman bowled Afzal's middle wicket to leave Hong Kong needing nine runs to win off nine balls.
Haseeb Amzad negotiated the nervy moment to get Hong Kong home.
Mahmudullah picked up 2-13.