Usman Khawaja made a magnificent resilient hundred before Tim Paine and Nathan Lyon denied Pakistan as Australia produced a monumental rearguard action to draw the first Test in Dubai.
Pakistan needed seven wickets on the final day to go 1-0 up in the two-match series after Australia resumed on 136-3, needing a highly unlikely 462 to win, but Khawaja (141) and Travis Head (72) frustrated them with a fourth-wicket stand of 132.
Khawaja made the highest scoring in the fourth innings of a Test in the United Arab Emirates, spending 524 minutes at the crease - taking him to 767 in total - in a heroic 302-ball knock, but the tourists looked to be heading for defeat when Yasir Shah took three late wickets.
Pakistan had 12.2 overs to claim the two wickets they needed for victory after Yasir (4-114) removed Khawaja, Mitchell Starc and Peter Siddle in quick succession, but Paine (61 not out) and Lyon (5no) dug in under pressure to complete a great escape, Australia closing on 362/8.
Australia collapsed with a whimper in the first innings, but Islamabad-born opener Khawaja - who top scored with 85 in the first innings - batted with remarkable application and skill as he and Head ensured no wickets fell in the morning session.
Pakistan struck twice before tea and although Yasir produced a huge twist late in the day, Paine faced 194 balls in a brilliant captain's knock and Lyon also showed great character to rescue Australia.
Head fell without scoring in his first Test innings but made amends by offering great support for Khawaja, who continued to take a positive approach against the spinners.
Khawaja played with great authority and Head reached his half-century after Pakistan opted against reviewing when he was struck on the pad, replays showing he would have been on his way.
Pakistan felt aggrieved when Khawaja was still there after a sharply turning delivery from Haris Sohail rapped him on the pad, the ball hitting the opener just outside the line of off stump, and Australia moved on to 215-3 at lunch.
Mohammad Hafeez got the elusive breakthrough just after the break, trapping Head bang in front from the first delivery with the new ball to end a gritty 175-ball knock.
Khawaja twice lofted Hafeez down the ground for boundaries which moved him into the 90s and the left hander punched the air as he jumped for joy after a quick single took him to three figures for the sixth time in the longest format.
Marnus Labuschagne danced down the wicket to launch Hafeez for six over mid-off, but paid the price for going back to a quicker leg break from Yasir, who pinned the all-rounder in front of middle stump.
Paine walked to the middle with Australia 252-5 and got his eye in after a shaky start, Khawaja still going strong and looking fresh as they saw it through to tea - Pakistan opener Imam-ul-Haq off the field with his finger in a brace.
Pakistan were out of reviews when Sarfraz Ahmed called for a review for lbw, Paine getting an inside edge on an off break from Bilal Asif, but Yasir ended a 79-run stand by snaring the magnificent Khawaja leg before.
It appeared that Khawaja's tour de force would be in vain as Babar Azam took a brilliant catch at short leg to see the back of Starc and Siddle also fell to Yasir without scoring in the same over.
Lyon and Paine stayed cool under pressure in the heat, though, surviving a few close calls to prevent what looked certain to be a Pakistan win.
|BREAKING NEWS: Shaw signs Manchester United extension|
|Jones lays down challenge to snubbed England star Cipriani|
|West Ham´s Pellegrini rejects Dzeko speculation|
|Emery fails to assure Ramsey of Arsenal future|
|Pakistan on course for victory after Babar 99 and farcical run out|
|Canelo ready to leave comfort zone to face Fielding|
|Eriksen ready for Tottenham return, Pochettino confirms|
|Titans coach rocked by Hurrell´s Rhinos switch|
|Rubin Kazan suspended from UEFA competition for FFP breach|
|Real Madrid could sack Lopetegui if results don´t improve, says Essien|
|On-court coaching would add to drama - Mouratoglou|
|Babbel lauds ´top class´ Ronaldo after Juventus switch|
|Carmelo Anthony: Rockets bench role challenging mentally|
|Maqsood preferred to Amir in Pakistan T20 squad|
|Make Ramsey Arsenal captain, don´t let him leave – Wilshere|
|Kaneria admits guilt in spot-fixing case|
|No coach can work miracles – Ibrahimovic defends under-fire Mourinho|
|Morgan earns England recall, Cipriani overlooked|
|Reavie leads CJ Cup, solid start from Koepka|
|Juventus kicked me out to sign Ronaldo – Higuain|
|England forward Hughes given six-week ban|
|Injured Halep withdraws from WTA Finals|
|Ronaldo exit makes all the difference for Real Madrid – Luxemburgo|
|Manchester United´s Chelsea Blues and other one-sided rivalries|
|Babbel fears for Kovac´s Bayern future|
|Bradley homers again, Red Sox take 3-1 lead over Astros|
|Ayton, Doncic shine on NBA debuts|
|Leonard focusing on future after Raptors debut|
|MLS Review: Rooney stunner seals DC win, Sounders clinch play-off spot|
|Pochettino ´proud´ of Dier for Ramos tackle|
|Wallabies name three uncapped players for All Blacks clash|
|Lakers coach Walton will monitor LeBron´s minutes, plans to use deep rotation|
|Lloris: United´s Pogba unfairly judged because of transfer fee|
|´Phenomenon´ Mbappe deserves Ballon d´Or, says Buffon|
|Dodgers on cusp of World Series after beating Brewers|
|Mata braced for ´difficult month´ at Man United|
|WATCH: Rooney scores wonderful free-kick for DC United|
|Kaino handed five-week ban for striking Roberts|
|Bears star Khalil Mack ´day-to-day´ with ankle injury|
|Anthony has ´a clearer understanding´ of his role with Rockets|
|Brewers remove Miley after one batter against Dodgers|
|Rams rule out Kupp for 49ers game|
|Giants owner Mara to talk with Beckham Jr|
|Bamberg battle back to claim Champions League win|
|MLB investigated alleged Astros sign stealing, found no wrongdoing|
|Timberwolves star Wiggins to donate $22 for every point this NBA season|
|Red Sox´s Sale won´t start game five of ALCS|
|Tsitsipas and Shapovalov advance at Stockholm Open|
|Witsel to Dortmund is signing of the season - Martinez|
|Pique confident Nadal will play in 2019 Davis Cup|
|Seeds suffer in Moscow and Luxembourg|
|Johnstone grabs hat-trick as England ease past France|
|Pogba and Mourinho disagreement over Instagram video, confirms Pereira|
|Nuggets coach Malone signs contract extension|
|Mayweather accepts Khabib´s challenge: ´We´re fighting´|
|Slovenia sack Kavcic as head coach|
|Morgan and Rashid star as England win rain-reduced ODI in Sri Lanka|
|Romagnoli aims to make Gattuso proud in Milan derby|
|Naldo signs Schalke extension|
|Bills to start quarterback Anderson against Colts with Allen out|
|O´Sullivan makes 147 at ´hellhole´|
|Barcelona know when captain Messi is angry – Abidal|
|Bertens loss hands Pliskova last WTA Finals berth|
|Liverpool star Mane undergoes hand surgery|
|F1 Raceweek: Happy hunting ground for title-chasing Hamilton - US GP in numbers|
|Canelo signs record-breaking DAZN deal|
|England hit by another Vunipola injury absence|
|Gruden: Oakland Raiders ´aren´t tanking´|
|Chiesa focused and happy at Fiorentina|
|We´ll see what´s possible - Henry not limiting Monaco´s ambitions|