Chasing a target of 177, the hosts looked out of it when they slumped to 6-108 but an unbroken 69-run stand for the seventh wicket between Shanaka and Chamika Karunaratne revived the innings. Sri Lanka then needed 59 runs off the last three overs and went on to win with one delivery to spare.
Shanaka’s 54 came off just 25 deliveries as he hit five fours and four sixes.
Australia had already secured the series, having won the first two games in Colombo.
Shanaka had been under pressure leading into the game as Sri Lanka had lost nine out of 10 games this year under his captaincy, but gave the capacity crowd something to cheer about with his audacious stroke play.
“It took me a few balls to settle in. Just wanted to hang in there and finish the game and pretty happy with the effort,” Shanaka said.
“Leading up to the game I tried to motivate the boys telling them that although we had lost the series, we needed some momentum leading up to the ODIs. I’m glad they delivered. It’s been a tough few months.”
The momentum changed in the 18th over bowled by Josh Hazlewood. He had been Aaron Finch’s most trusted bowler in the series and his first three overs had cost just three runs. But 22 runs were scored in his fourth over, Shanaka hit two consecutive sixes and followed it up with two more fours.
That brought the equation down to 37 runs in two overs and the penultimate over bowled by Jhye Richardson went for 18 runs, leaving Sri Lanka needing 19 in the last over.
Kane Richardson struggled under pressure as he sent down two wides to start the over. With Sri Lanka needing 15 runs off four balls, Australia still had things under control. But Shanaka hit two boundaries off the third and fourth deliveries of the over and now Sri Lanka required seven runs in two balls.
The penultimate delivery was hit straight down the ground to bring up Shanaka’s half-century to level the scores. Richardson’s next delivery was a wide and that handed Sri Lanka a sensational win.
“That was an unbelievable knock by Dasun tonight,” Australia captain Aaron Finch said. “We thought batting first was OK. I don’t think us batting first today had any reason for the defeat. Dasun played really well.”