Maharaj became just the second South African and first in more than 60 years to take a test hat trick when he dismissed Kieran Powell, Jason Holder and Joshua Da Silva in the second-to-last over before lunch on the fourth day.
West Indies was already under pressure after fast bowler Kagiso Rabada's three wickets at the top of the order.
But Maharaj hurried the home team's demise in St. Lucia as it was all out for 165 before tea on the fourth day, well off the target of 324 set by South Africa.
Maharaj also wrapped it up when Jayden Seales was caught out on the square leg boundary to give the left-arm spinner his fifth. Roston Chase wasn't able to take his place at No. 4 because of a leg injury, meaning West Indies had only nine batsmen.
Maharaj's three in three balls started with a key breakthrough when Powell holed out at square leg for 51. Maharaj added the wickets of Holder and Da Silva, with Wiaan Mulder's low one-handed catch down to his right at leg slip sealing the hat trick. It sent Maharaj running and sliding, soccer-style, on his chest on the grass in celebration.
The only previous South African to take a hat trick in tests was Geoff Griffin against England at Lord's in 1960.
West Indies started the day 15-0 but lost captain Kraigg Brathwaite (6) and Shai Hope (2) quickly to the pace of Rabada.
Powell and Kyle Mayers (34), who was pushed up to No. 4 in place of Chase, resisted and their 64-run stand looked set to take West Indies to lunch without any further damage.
Mayers' error in trying to pull across the line against Rabada, and sending a catch looping up for Dean Elgar, let South Africa in.
From 90-2, West Indies slid to 109-6 in the seven overs leading up to lunch. West Indies didn't make 200 in any of its four innings of the series.
South Africa clinched its first series win away from home since March 2017 and gave Elgar a successful start in his first series since being appointed captain. (AP)