A relieved Australia captured Pakistan's last two wickets to win a captivating first day-night test in Brisbane by 39 runs on Monday but the touring side won huge admiration for their dogged fourth innings resistance.
Chasing a test record 490 for victory, Pakistan had resumed the fifth and final day on 382 for eight and paceman Mitchell Starc proved the game-breaker when he ended a stubborn 71-run ninth-wicket partnership between Asad Shafiq and Yasir Shah.
Starc struck with a searing delivery that pinged off Shafiq's glove for an easy catch to David Warner in the gully, bringing to an end a heroic knock of 137.
Yasir fell moments later to seal the win, run out by home skipper Steve Smith with a direct hit for 33, having failed to ground his bat after an aborted single as Pakistan were eventually dismissed for 450.
Australia take a 1-0 lead in the three-match series but Pakistan showed impressive fight to turn the match into a cliffhanger and will head to the second game in Melbourne on Dec. 26 with renewed confidence.
Starting the day needing 108 runs to win but with only two wickets intact, the tourists maintained a sliver of hope with middle-order batsman Shafiq at the crease after he cleaved a magnificent unbeaten century on day three.
Australia's nerves were becoming increasingly frayed as Pakistan approached their target but the relief was palpable when they finally sealed a victory that looked a formality a day earlier.
"I lost all my fingernails, I think," joked Smith. "Some game of cricket, wasn't it?
"Credit's got to go to our bowlers, they really stuck at it and got us over the line.
"That wicket, I guess, of Asad showed the class of Starcy with a ball that was 60 overs old and quite soft.... but what a game of cricket."
Australia appeared bemused to even be competing on day five and it manifested itself in Smith's conservative field settings.
Shafiq and Yasir cantered past 400 and the Australian captain became fidgety as his front-line bowlers were despatched regularly through the gaps.
Slow bowler Nathan Lyon was introduced and coaxed a nick from Yasir which pinged off his pad and flew just wide of Peter Handscomb at short leg.
Growing in confidence, Yasir then whipped paceman Jackson Bird off his pads for four at the square leg boundary to bring up the 50-run partnership with Shafiq.
Yasir then survived a missed stumping, a dropped catch and overturned an lbw decision by umpire Richard Illingworth before Starc timed his intervention to perfection at the other end with a searing, short-pitched delivery that reared up on Shafiq.
Shafiq was named man-of-the-match following his ninth test century, the most ever for a number six batsman.
"The way the team, all the batsmen showed their character, that was wonderful," Pakistan captain Misbah-ul-Haq said.
"Asad Shafiq, that was a superb knock.
"So, a lot of positives, and I'm happy and proud the way the team played."
(Reporting by Ian Ransom in Melbourne; Editing by John O'Brien)