Miller plundered a robust 85 not out off 72 balls to steer South Africa to 223-7 after unorthodox spinner Ajantha Mendis had reduced the tourists to 154-7 in the 42nd over.
Tsotsobe then ripped through Sri Lanka's top order with three wickets in the space of six runs before finishing with 4-22 as the hosts were bundled out for 167 in the day-night game.
The victory ended South Africa's 11-match losing streak in one-day cricket on Sri Lankan soil and gave AB de Villiers' tourists a badly-needed win in the current series.
With Sri Lanka 2-1 ahead, South Africa must also win the fourth match at the same venue on Sunday to take the series into the decider in Colombo next Wednesday.
Thisara Perera lit up the gloomy evening for the hosts by smashing five sixes and a boundary in the 33rd over sent down by left-arm spinner Robin Peterson.
With the second ball declared a wide, the 35 runs taken in the over fell just one run short of the world record of six sixes hit by South African batsm