Brisbane: Australia were two wickets from victory at the end of day four of the first day-night test against Pakistan on Sunday, but the tourists were buoyed by a feisty fourth innings chase and a brilliant unbeaten century from Asad Shafiq.
Pakistan were eight for 382 at stumps, 108 runs short of their victory target, but having won admiration with the highest fourth innings total at the Gabba.
Shafiq was 100 not out, after anchoring three stubborn partnerships, while Yasir Shah was on four at the end of a rain-interrupted day.
Shafiq will be key to Pakistan's faint hope of stealing a famous victory, the tourists having been set an improbable chase of 490.
Australia captain Steve Smith was berating himself for grassing two catches in the slips in the final session.
The second, off Mitchell Starc's bowling, would have dismissed Shafiq for 72 and left the tail-enders to fend for themselves.
Smith demanded an extra eight overs to push for the win and was finally rewarded when the eighth wicket fell in the final over.
He pouched a much harder chance in the slips when paceman Jackson Bird had Wahab Riaz nick behind after a swashbuckling 30 that featured two slog-swept sixes over the midwicket fence off spinner Nathan Lyon.
Shafiq was majestic in his 140-ball knock, cleaving boundaries to all corners of the ground and rotating the strike to defy Australia's fatiguing attack.
He shared in a doughty seventh wicket stand with Mohammad Amir before Bird broke the 92-run partnership when Amir nicked behind for 48.
Left-arm seamer Starc, who ended a 91-run stand between Azhar Ali and Younus Khan, also halted a 47-run effort between Shafiq and wicketkeeper Sarfraz Ahmed for the sixth wicket.
The rangy Starc fired in a gem of a delivery to bowl Sarfraz through the gate for 24.
Shafiq was dropped on 58 after smashing square to a diving Usman Khawaja and later slashed three runs to point off Bird to complete his stellar hundred.
Brief scores
Australia - 429 and 5 for 202 dec (Khawaja 74, Smith 63)
Pakistan - 142 (Sarfraz 59*, Hazlewood 3-22, Bird 3-23, Starc 3-63) and 8 for 382 (Shafiq 100*, Azhar Ali 71, Younis 65, Bird 3-94, Starc 3-97)
Status - Pakistan require 108 runs to win