Mustafizur picked up 4-21 while Shakib added 3-24 as the visitors in Mashrafe's final T20 match dismissed Sri Lanka for 131 runs in 18 overs after scoring 176-9.
The win, which ended Bangladesh's eight-match losing streak in this format, also helped the side secure a draw in the two-match series after they lost the opening game by six wickets on Tuesday.
"I am feeling proud to have played with these boys and the support staff. Big thanks to my cricket board and my family," Mashrafe said in choked voice.
It spoiled Lasith Malinga's hat-trick as the veteran fast bowler with a sling action finished with 3-34, stopping Bangladesh's scoring spree and providing Sri Lanka a chance for their third successive series win.
Chamara Kapugedara offered some resistance with the bat for the hosts, hitting 50 off 35 balls.
Shakib, who took two wickets in his first two overs, returned in his second spell to remove Perera and break the stand before Mashrafe bowled Seekkuge Prasanna (11) to dent Sri Lanka's hopes in his final game.
High-flying Bangladesh eye rare glory away from home
Mustafizur dismissed Kapugedara and Malinga in the next over to take Bangladesh close before rookie pace bowler Mohammad Saifuddin completed the team's second ever win against Sri Lanka.
Malinga was the star of the show earlier in Bangladesh's innings when he became only the fifth bowler in the history of T20 internationals to claim a hat-trick.
In the penultimate over of the innings, Malinga bowled Mushfiqur Rahim and Mashrafe and trapped debutant Mehedi Hasan lbw to halt Bangladesh from piling up a massive total.
His feat, the second Sri Lankan to achieve the mark after teammate Thisara Perera, spoiled a good start by Bangladesh, who at one stage looked well set to score 200 runs after a rollicking start.
Mashrafe Mortaza announces retirement from T20Is
Imrul Kayes and Soumya Sarkar added 70 runs in a record opening partnership to set the platform for a big total after skipper Mashrafe won the toss and opted to bat first.
"It is disappointing. We did not get a good start and unfortunately lost five wickets in the first six overs," said Sri Lanka captain Upul Tharanga.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ