The hosts faced a difficult challenge with 59 required in the final three overs. Shanaka, though, refused to give up and put on a superb batting show, taking Australia's bowlers to task.
At Pallekele International Cricket Stadium on Saturday, captain Dasun Shanaka's quickfire knock (54 not off 25) enabled Sri Lanka beat Australia by four wickets in the third T20I and avert a clean sweep in the three-match series.
Australia chose to bat first after winning their third toss in a row, with Josh Inglis replacing Mitchell Marsh, who went out with a slight calf strain.
The Sri Lankan government, as well as fans, had begged with the Australians to hold the cricket series since it is projected to bring in much-needed foreign cash.