Mitchell Johnson and Steven Smith hit resolute half-centuries to delay Pakistan's victory bid in the first Test here today.
At tea Johnson was unbeaten on 54 and with him number ten Peter Siddle was batting on four as Australia, on 196 for eight, needed to bat another 29 overs to force a draw.
Pakistan, who set a 438-run target, need two more wickets for a 1-0 lead in the two-match series.
More From This Section
The defeat looked inevitable with Australia reeling at 117-7 at lunch but Smith (55) and Johnson defied the spinners during their 65-run stand for the eighth wicket.
Babar threatened to dismiss Smith twice but Sarfarza missed a stumping with the batsman on 37 and Misbah-ul Haq failed to pick a difficult chance at 44.
Babar also saw Ahmed Shehzad drop Johnson at deep square leg on 23 and two runs later by Yasir Shah as both the batsmen frustrated the Pakistani attack.
Smith hit Shah for his third four to reach his seventh half-century but fell five runs later, caught at short-leg.
Smith resisted for 175 balls.
It was Babar who struck twice before lunch to bring Pakistan closer to victory.
Australia had resumed on 59-4 but Chris Rogers (43) and Smith added 32 in the first hour before paceman Imran Khan made the breakthrough, bowling Rogers who played over the delivery.
Babar then came into his own, removing Mitchell Marsh (three) with a turning delivery. The edge was well taken at short cover by Azhar Ali.
Four overs later, Babar spun one across Brad Haddin's forward push to hit the stumps and dismiss the wicketkeeper for a duck as Australia lost their seventh wicket for 105.
Babar's previous best figures were 3-89 against South Africa in his debut Test in Abu Dhabi last year.
Australia's top order, including captain Michael Clarke, had flopped on the fourth evening, with Babar and leg-spinner Yasir Shah causing the damage.
But Pakistan have dominated the game throughout, piling up 454 and 286-2 declared while Australia scored 303 in their first innings.
The second and final Test starts in Abu Dhabi on October 30.