Pakistan beat Australia in their final Super Eight match at the World Twenty20, a result that saw both teams progress to the semi-finals.
Chasing 150 for victory, Australia were left bamboozled by Pakistan's plethora of spin bowling options and had Mike Hussey (54 not out) to thank for guiding them past the 112 target which guaranteed their progress from Group Two on net run-rate.
India's one-run victory over South Africa in the final Super Eight match later in the day confirmed Australia as group winners and ensured Pakistan also advanced to the semi-finals on net run-rate. Australia, Pakistan and India each finished with four points.
Hussey stood firm as his team-mates failed a stern trial by spin and saw Australia up to 117-7 after Pakistan had posted 149-6.
Saeed Ajmal took his wicket haul in the tournament up to eight with 3-17 as all seven Australia wickets fell to spin.
Mitchell Starc had earlier claimed three wickets of his own to restrict Pakistan, for whom Nasir Jamshed (55) struck his second half-century of the tournament.
Pakistan face hosts Sri Lanka on Thursday and Australia take on West Indies on Friday in the semi-finals.
After winning the toss Australia opted to bowl first, something they have now done in all six matches this tournament.
Left-arm paceman Starc struck with his first ball, getting a full delivery to tail beautifully back into the right-handed Hafeez, who was trapped plumb lbw for only four.
The Pakistan captain should have been joined back in the pavilion by Jashed in the same over, however Glen Maxwell was guilty of dropping a routine catch at first slip to hand the left-hander a life.
It proved a costly miss as Jamshed steadily built an innings which brought Pakistan back into the match after Shane Watson had made Imran Nazir his 11th wicket of the tournament.
Jamshed and Kamran Akmal added 79 for the third wicket and the former brought up his second half-century of the competition off 41 balls with a thumping boundary back down the ground off Brad Hogg.
The classy left-hander holed out to Dave Warner off the bowling of Xavier Doherty in the 15th over but had helped lay a platform on which Akmal brothers Kamran and Umar could build.
Kamran failed to do so, though, drilling Starc straight to Cameron White at extra cover two balls later when poised on 32, while Umar faced just eight balls to finish unbeaten on nine.
Abdul Razzaq, recalled into the side in place of Yasir Arafat, announced himself with a couple of huge hits but fell for 22 in the penultimate over when outfoxed by a Pat Cummins slower ball.
Starc took Shahid Afridi's leg-stump out of the ground in the final over and Pakistan scraped to just 149-6, meaning Australia needed only 112 to qualify for the semi-finals.
Australia suffered a double setback in the run-chase when Watson, the tournament's leading run-scorer, was trapped lbw by Raza Hasan in the fourth over having made only eight and Warner followed in similar fashion to Hafeez eight balls later.
Captain Bailey joined Mike Hussey in the middle with his side wobbling on 19-2 and Pakistan continued to squeeze the life out of the batting side with 17 successive overs of spin.
Bailey, White and Maxwell all departed in quick succession in the middle overs and Australia's future in the competition looked in serious danger when on 68-5.
But Hussey, as he has done so many times over the years, stayed calm under intense pressure, making sure Australia reached the 112-run target with ensured their progress at the start of the final over with a boundary off Umar Gul.
Pakistan could qualify for their fourth successive World T20 semi-final even if India beat South Africa at the same venue later on Tuesday, however it will all depend on the shift in net run-rate.