Captain Babar Azam's first test hundred in two years and Abdullah Shafique's 71 led Pakistan's resistance after Australia set up a huge target of 506 on day four Tuesday of the second test.
Babar was unbeaten on 102 off 198 balls and opening batter Shafique followed his maiden test hundred in the drawn first test with an undefeated 71 off 226 balls to take Pakistan to 192-2 at stumps.
Pakistan still needs an improbable 314 runs to achieve a world record run chase on the last day or survive the remaining 90 overs to deny Australia taking a 1-0 lead in the three-match series.
Babar and Shafique defied Australia's reverse swing and Nathan Lyon's spin on a wearing pitch for well over four hours and raised a 171-run stand in almost two sessions.
Babar, who made his last test century in February 2020 against Bangladesh, raised his sixth test hundred when he top-edged a sweep for two runs late in the last session.
It took him just over four hours off 180 balls with 12 fours.
“We have good momentum, but there are already rough patches on the wicket and it will be a big challenge for us tomorrow,” Shafique said.
Babar and Shafique joined in the second over after lunch when Azhar Ali's labors for more than an hour to score 6 were undone by an lbw from Cameron Green.
Video showed a spike coming off the gloves before it hit Azhar on the body, but he chose not to review.
Pakistan could have been 38-3 but Steve Smith spilled a straightforward catch in the slips when Shafique was on 20.
It was Smith's third dropped catch in the test.
Shafique also got a life on 33 when he was well short of his crease but Green missed the stumps at the non-striker's end.
Babar hit Pakistan's first boundary of the innings in the 26th over by cutting Mitchell Swepson to the point boundary and then grew in confidence against the pace of Mitchell Starc, who was used in short spells.
Shafique also opened up by pulling Pat Cummins to the midwicket boundary and lofting Lyon over long on for a six.
Both batters carried Pakistan home without further damage, including the last overs with the new ball.
Pakistan's highest successful chase in test matches is 382-3 in 2015 when it beat Sri Lanka by seven wickets at Pallekele.
“We are still in a position to win the test match," Australia batting coach Michael Di Venuto said.
“Yesterday, we got reverse swing going with the hard ball, but today (Babar and Shafique) got through that period and once the ball got softened they played very well."
Earlier, Australia extended its lead to 505 when Cummins declared the second innings at 97-2 after Marnus Labuschagne, on 44, played Shaheen Afridi back onto his stumps off a mistimed pull shot.
Afridi and Hasan Ali didn't allow first innings century-maker Usman Khawaja, 44 not out, and Labuschagne to score quickly in the half hour after Australia resumed on 81-1.
The declaration came earlier than expected.
It was only the second time Australia declared both innings in a test in Asia; the other was in 1986 against India at Chennai.
It gave Australia almost two full days and a minimum of 172 overs to take a 1-0 lead in the series at the fortress of Pakistan -- National Stadium -- where the home team has lost just two out of 44 test matches.
Those losses were against South Africa in 2008, and England in 2000.
Australia routed Pakistan for 148 in the first innings on day three in just under 4 1/2 hours after it declared its first innings at 556-9 by keeping Pakistan on the field under hot conditions for more than two days.
(Reported by AP)