Australia have pulled off one of the greatest escapes in Test history, with an Usman Khawaja fourth-innings epic sealing the unlikeliest of draws against Pakistan in Dubai.

In one of the most tense climaxes to a Test in recent memory, Usman Khawaja batted 302 balls across the fourth and fifth days of the series-opener before captain Tim Paine (61 not out from 194 balls) and No.10 Nathan Lyon (five not out off 34 balls) iced an incredible stalemate.

It was the longest (in terms of overs) Australia have ever batted in a fourth innings to hold on for a draw, let alone in Asia, and against a world-class spin attack on a wearing fifth-day pitch. Yasir Shah (4-114), after going 52 overs without taking a wicket, looked like he might spin Pakistan to a late victory as he took advantage of a worn pitch to remove Khawaja for 141 and then tailenders Mitchell Starc (one) and Peter Siddle (duck) in the space of eight balls.

But Paine and Lyon were up to the task as Australia finished on 8-362 after 139.5 overs. Debutants Travis Head (72 off 175 balls) and Aaron Finch (who scored 49 off 99 on day four) both played vital knocks, but it was the resolute Khawaja who was the hero, dismissed in the final session having spent all but two hours of this Test either batting or fielding. Only three Australians have faced more balls in the fourth innings of a Test.

His 8hr 39min knock was also the second-longest by a player in a fourth innings in Test history. He spent 12 hours and 40 minutes at the crease for the whole Test, having struck 85 in the first innings. Australia's escape represents a major blow for Pakistan, who had declared on day four to leave themselves the best part of five sessions to take the 10 wickets their opponents had given up for just 60 runs in the first innings. It also means the Aussies have kept their hopes of a first Test series victory in Asia in seven years alive, with the second Test in Abu Dhabi to get underway Tuesday.

Full of optimism, Australia begun the day with Khawaja and Head picking up from their assured stint late on day four. The pair batted with composure through the opening session of the day, continuing the trend of the morning session proving the best time to bat; only three wickets fell in the five morning sessions in this Test. Head was fortunate to survive an lbw shout while sweeping on 44 off Yasir, with Pakistan's failure to review leaving coach Mickey Arthur visibly exasperated.

It was an important half-century for Head after his first Test innings on day three lasted just nine balls, bringing up the milestone off 117 balls. Khawaja meanwhile managed to weather Mohammad Abbas during an intriguing battle, with the Pakistan paceman consistently beating his outside edge before lunch in a brilliant display of reverse-swing bowling.

After a 137-run stand, it was the introduction of the new ball that immediately undid Head. Mohammad Hafeez had only bowled two overs to that point and while Head had been ably handling increasing amounts of turn from Bilal Asif and Yasir, the veteran allrounder's straight ball had Head stuck on the crease as it cannoned into his pad. Marnus Labuschagne, also coming off a first-innings duck, appeared increasingly comfortable in his stead as he deposited Hafeez for six over long-on but he too departed to a straight one, handing Yasir a first wicket of the game.

That wasn't before Khawaja had raced to his century. After dispatching Hafeez twice for four back over his head to move from 87 to 91 and then to 95, he moved into triple-figures with a quick single to mid-off to earn strong applause from teammates, family and the smattering of spectators braving the 39-degree heat. Paine survived a number of shaky moments early with the bat, as did his partner when the captain struck one firmly to Azhar Ali at mid-off and was late on his call of 'no', leaving Khawaja scrambling to make his ground.

A direct hit would have had him cold and left Australia's efforts in tatters. But Paine grew in confidence as the game moved into a tense final session. Pakistan, with no reviews left, bellowed ferocious appeals at every half-chance. Sarfraz Ahmed tried everything; he rotated his tiring attack around, changed the ends they bowled from, moved fielders and just as Paine and Khawaja looked like they'd blunted every possible manoeuvre, Yasir struck.

Having swept and reverse-swept the leg-spinner so effectively, the shot finally proved Khawaja's downfall as he was adjudged lbw to a wrong-un and his review came back with bad news. As the club cricket cliché goes, one was always likely to bring two. An astonishing, leaping catch from Babar Azam at short leg accounted for Starc, while Siddle was trapped lbw.

With three late scalps, Yasir had saved his brilliant best for the very end of this Test and Pakistan again sniffed victory. There were no shortage of nervy moments in the game's dying minutes; Paine twice edged balls that shaved his stumps, while Lyon survived a strong shout for a bat-pad catch in the penultimate over.

So it all came down to the final over as all nine of Pakistan's fielders gathered around Australia's skipper. With No.11 Jon Holland scarcely able to watch, Paine safely saw out the five balls from Yasir to tie a bow on an extraordinary Test match.

Australia: Aaron Finch, Usman Khawaja, Shaun Marsh, Mitchell Marsh, Travis Head, Marnus Labuschagne, Tim Paine (c & wk), Mitchell Starc, Peter Siddle, Nathan Lyon, Jon Holland Pakistan: Imam-ul-Haq, Azhar Ali, Haris Sohail, Asad Shafiq, Babar Azam, Mohammad Hafeez, Sarfraz Ahmed (c & wk), Bilal Asif, Mohammad Abbas, Yasir Shah, Wahab Riaz