It became 136 for four after Rassie van der Dussen and Heinrich Klaasen fell for 21 and 12 respectively as Pakistan fought hard against a batting unit that has been in formidable form this tournament.
When David Miller and Marco Jansen - moments after launching Haris Rauf down the ground for six - departed they Proteas still needed 36 to win with four wickets remaining.
Usama Mir then got the prized wicket of Aiden Markram for 91, and he was followed quickly back to the changing rooms by Gerald Coetzee, caught behind off Shaheen Shah Afridi (three for 45), with 21 now the target.
A brilliant one-handed caught and bowled from Rauf did for Lungi Ndidi with 11 required and, three runs later, number 11 Tabraiz Shamsi survived the narrowest of leg-before reviews.
But Maharaj made an invaluable seven not out, including the winning boundary, to get South Africa fell over the line.
Earlier, when Pakistan captain Babar Azam departed for 50 his side were wobbling at 141 for five.
But a run-a-ball 52 from Saud Shakeel led the counter-attack along with Shadab Khan, who made 43.
However, Shamsi finished with four for 60 as Pakistan were dismissed for 270 from 46.4 overs.
South Africa’s fifth win lifts them to the top of table, level on 10 points with hosts India having played a game more, while Pakistan’s semi-final hopes are hanging by a thread after a fourth defeat.