Despite the defeat, Australia also advanced to join Sri Lanka and West Indies in the last four with a superior net run-rate after beating India and South Africa in their earlier Super 8 matches.
India missed out on the semi-finals despite beating South Africa by one run in a gripping final Group 2 match.
Their total of 152 for six was not enough because they were unable to restrict already eliminated South Africa to fewer than 121 runs. When South Africa passed that mark in the 17th over, it ensured Australia and Pakistan would move into the last four.
Ajmal, the Pakistan off-spinner, took three Australia wickets for 17 while man-of-the-match Hasan picked up two for 14 runs as Australia could only manage 117 for seven in their 20 overs, chasing 150 for victory.
Hafeez thanked his bowlers for rising to the occasion after the eight-wicket defeat against arch-rivals India on Sunday.
"Everybody realised that we have to win the game and win with a margin," Hafeez said during the post-match presentation ceremony. "I am grateful to see the effort of the boys. Every bowler did a great job for Pakistan. We wanted our bowlers to do the job and we got the total we wanted."
The Australia middle-order struggled once their openers Shane Watson and David Warner were dismissed early. Left-hander Mike Hussey's unbeaten 54 proved crucial as it took Australia past the 112-run mark required to ensure that they advanced to the semi-finals. Hafeez also picked up two wickets as he used five spinners to complete 18 out of the 20 overs in the Australian innings.
George Bailey, the Australia captain, acknowledged that his team had failed the spin test. "Pakistan completely outplayed us; they took early wickets to put pressure on us and they have some quality spinners," he said.
"To this point we have been really consistent so the challenge now will be to get back to that form for the semi-finals."
Put in to bat, Nasir Jamshed compiled a fine 55 to take Pakistan to 149 for six wickets, despite a fiery spell of fast bowling from the left-arm seamer Mitchell Starc, who took three for 20 runs.
Kamran Akmal made 32 and added 79 runs for the third wicket with Jamshed to give Pakistan some momentum after a slow start.
Hosts Sri Lanka will meet Pakistan in the first semi-final in Colombo tomorrow and Australia take on the West Indies on Friday in the same stadium.
The final will take place on Sunday also in Colombo.
Contextual targeting label: