The 22-year-old pacer claimed Bangladesh's last three wickets before finishing with 3-26 as Sri Lanka defended their modest score of 221 runs by bowling out Bangladesh for 142 in 41.1 overs.
Madushanka took the wickets of Rubel Hossain and Mashrafe Mortaza in the last two balls of his sixth over before he removed Mahmudullah Riyad in the next over to complete his hat-trick.
He joined South Africa's Kagiso Rabada, Bangladesh's Taijul Islam and team-mate Wanidu Hasaranga who have also achieved the rare feat.
Medium pacer Dushmantha Chameera and spinner Akila Dananjaya claimed two wickets each for Sri Lanka.
"We are over the moon... the guys put their heart and soul in the practices and then when they go in to the middle they put their heart and soul," said Sri Lanka captain Dinesh Chandimal.
"They had the plans and they executed well, and credit goes to everyone who played the series."
"When he fell, we were sure he wouldn't be playing. We saw his hand. We knew it wasn't possible for him to bat. So we had asked the others not to think about it. I wouldn't use it as an excuse when chasing 220-odd runs," he said.
"Everyone is disappointed in the dressing room. We expected to win having come this far," he added.
Earlier, fast bowler Rubel claimed four wickets to help Bangladesh dismiss Sri Lanka for 221 runs on a sluggish pitch at the Sher-e-Bangla National Stadium.
Upul Tharanga top-scored with 56 off 99 balls while skipper Dinesh Chandimal added 45. Wicketkeeper-batsman Niroshan Dickwella made 42.
Sri Lanka will now play two Test matches against Bangladesh with the first Test beginning in the port city of Chittagong on January 31.
The Test series will follow two Twenty20 internationals between the two teams.
Disclaimer: No Business Standard Journalist was involved in creation of this content
