Australia, chasing a challenging 268 for victory, were bundled out for 161 before tea to trail the three-match series 0-1. Steven Smith top-scored with 55.
Sri Lankan batsman Kusal Mendis set up the win for the hosts with his superb maiden ton in his team’s second innings after the home side overcame an 86-run deficit.
Resuming day five needing 185 to win at the Pallekele Stadium with seven wickets in hand, the world champions were dismissed for 161, leaving Steve Smith with his first loss in 12 Tests as skipper.
Left-arm spinner Rangana Herath, 38, was the chief tormentor, claiming 5-54 and overall nine wickets in the match. Left-arm wrist spinner Lakshan Sandikan finished with 3-49 in his debut match.
The home team made to work hard when Peter Nevill and the injured Steve O’Keefe grimly fought on. Without caring about scoring, they combined for four runs off 178 balls, including 23 straight maidens, in 97 minutes long resistance. Neville was caught behind off a delivery of spinner Dhananjaya de Silva.