Maharaj returned career-best figures of 9/129, to become the 19th overall and only the second South African after Hugh Tayfield to achieve the rare feat.
The 199-run win, which came with more than a day to spare, was due to Sri Lanka's tireless spin trio of Herath, Akila Dananjaya and Dilruwan Perera who together claimed all 20 South African wickets. His effort is also the best against the Islanders by any opposition bowler.
At the break, South Africa trailed Sri Lanka by 319 runs on the first innings, with seven wickets in hand.
Dilruwan Perera enjoyed an eventful 36th birthday as he first spilled Dean Elgar and then twice dismissed the opener off no-balls before the finally sending him back for 37.
Theunis de Bruyn's gutsy century went in vain as Sri Lanka completed a 2-0 series sweep after Rangana Herath spun the hosts to a comprehensive victory against South Africa in the second and final Test on Monday.
Sri Lanka were 151-3 in the second innings with Dimuth Karunaratne and Danushka Gunathilaka adding 91 runs for the first wicket.
Sri Lanka ended the day with an emphatic lead of 365 runs.
At the wickets were Dimuth Karunaratne on 59 not out and Angelo Mathews on 12 not out.
Sri Lanka captain Suranga Lakmal soon declared on 275 for five, before unleashing his three-pronged spin attack who blew away the top half of the South African batting line-up. Dananjaya remained unbeaten on 43.