South Africa fell agonisingly short of recording the highest fourth innings total to win a Test match in cricket history in Johannesburg.
Chasing 458 for victory, the hosts made 450-7 at The Wanderers with Faf du Plessis and AB de Villiers both scoring centuries and sharing a 205-run partnership for the fifth wicket.
The Proteas needed just 16 off 20 balls when du Plessis was run out by a direct hit from Ajinkya Rahane at mid-off after making 134.
The hosts then abandoned their pursuit of the target with Vernon Philander and Dale Steyn blocking out consecutive overs from Zaheer Khan and Mohammed Shami before attempting slogs off the final four balls.
|South Africa 2nd Innings: 450-7 (136 Overs)|
|AN Petersen||b Mohammed Shami||76||204||162|
|GC Smith*||run out (Rahane)||44||126||126|
|HM Amla||b Mohammed Shami||4||26||13|
|F du Plessis||run out (Rahane)||134||309|
|JH Kallis||lbw b Khan||34||54||37|
|AB de Villiers†||b I Sharma||103||239||168|
|JP Duminy||b Mohammed Shami||5||8||9|
|VD Philander||not out||25||37|
|DW Steyn||not out||6||10|
|Extras||(b 2, lb 7, w 8, nb 2)||19|
The record total remains the 418 achieved by the West Indies when they beat Australia in Antigua in May 2003.
The hosts resumed on 138-2, needing 320 runs in the day for the most unlikely of victories and their quest was badly hurt when Alviro Petersen was clean bowled by Shami for 76 in just the fifth over of the morning.
Zaheer then became just the fourth Indian to take 300 Test wickets after Anil Kumble, Kapil Dev and Harbhajan Singh.
However, he was fortunate to remove Jacques Kallis for 34 as the umpire failed to spot a big inside edge.
South Africa were 197-4 at that point but du Plessis and de Villiers played majestically to bring up their third and 18th Test centuries, respectively, knocking off many records in the process.
By the time de Villiers had reached his milestone, the hosts needed 66 to win off the final 15 overs in the last hour of the game.
However de Villiers chopped on an Ishant Sharma delivery for 103 and JP Duminy's innings was brief, an inside edge off Mohammed Shami crashing into his stumps after he made just five.
Philander came to the crease with 51 needed and the seventh wicket pair looked likely to make history until a diving Du Plessis was left stranded by Rahane's throw.
It looked like there was plenty of drama yet to come but Steyn came to the crease seemingly with instructions to save the match, rather than win it, and that was met by jeers from the crowd.