At tea, the recalled Aslam was a Test-best 69 not out and Azhar, dropped twice, 72 not out in a total of 154 for one.
That left Pakistan 143 runs behind England's first innings 297.
Pakistan were none for one just four balls into their innings on Thursday when Hafeez fell for a duck after lazily guiding a short James Anderson delivery to Gary Ballance at point.
Now all eyes were on Aslam, also playing just his third Test, after the 20-year-old had been brought in to replace struggling opener Shan Masood.
Also Read
His only prior innings this tour had seen Aslam make just 17 against Worcestershire last week in a two-day warm-up match.
Azhar showed his class by calmly turning Anderson off his legs for four.
And when all-rounder Chris Woakes overpitched on his Warwickshire home ground, Azhar elegantly drove him through the covers for another boundary.
The stylish 31-year-old was equally severe when fast bowler Steven Finn dropped short, cutting him for four over point.
- Azhar dropped twice -
=======================
Off-spinner Moeen Ali received similar treatment, with Azhar cutting a rank short ball for four.
Those scores remained unaltered when Azhar, in a rare indiscretion, went for a flashing drive outside off stump against Anderson, only for Joe Root to drop the awkward second-slip chance to his left.
Another cover-drive, this time off Finn for three, saw Azhar complete a 129-ball fifty, including six fours, in nearly three hours at the crease.
Aslam's swept four off Ali then saw him to the landmark, his maiden Test fifty coming in 135 balls with five boundaries.
It was the start of a sequence of three fours in five balls from Ali for Aslam, including a lofted drive over the top of mid-on.
Azhar almost fell to a similar shot off Ali when on 68, but the bowler was unable to hold a tough return chance above his head off a hard-hit drive.
Wednesday saw Sohail justify both his inclusion, and Pakistan captain Misbah-ul-Haq's decision to field first, by taking a Test-best five for 96.
After the 32-year-old paceman sparked a top-order collapse, England were indebted to left-handers Ballance (70) and Ali (63) for getting them close to 300.