At stumps, England were 414 for five in their second innings, a lead of 311 runs. Bairstow was 82 not out and Ali 60 not out after they had added an unbroken 132 for the sixth wicket ahead of Sunday’s final day.
Pakistan will now have to set a new record for the Birmingham ground if they are to go 2-1 up in the four-match series, as the most any side have made in the fourth innings to win a Test at Edgbaston is South Africa’s 283 for five in 2008.
England had been well-placed at 120 without loss overnight. But openers Alastair Cook and Alex Hales both went early on Saturday as Pakistan took two wickets for no runs in nine balls.
Joe Root (62) and James Vince (42) stopped the rot during a painstaking stand of 95. Leg-spinner Yasir Shah struck either side of tea to dismiss Root and Gary Ballance.
But the pair’s Yorkshire colleague Bairstow, in at 257 for four, scored briskly and he received excellent support from Ali as they overpowered a tiring Pakistan attack featuring just four frontline bowlers.
England scored 152 runs in Saturday’s final session, after managing 142 runs in the first two sessions combined. “The way Cookie and Halesy played last night was outstanding,” Root told Sky Sports before turning to Bairstow and Ali’s stand.
“It was an unbelievable partnership tonight, good to watch and an exhibition of how to bat in the third innings.
“The pitch doesn’t look like it is breaking up, but there’s enough there to take 10 wickets tomorrow (Sunday).”
But Pakistan bowling coach Mushtaq Ahmed said: “I don’t know what England are going to do tomorrow (Sunday), but one thing is for sure: this is a good pitch for batsmen, and our batsmen are in good form.”
Play resumed Saturday with England captain Cook 64 not out and Hales 50 not out after they had erased a first-innings deficit of 103 with their maiden century stand in 18 innings as a Test-match opening pair.
But Pakistan soon removed both batsmen. Left-hander Cook (66) pushed out to first-innings five-wicket hero Sohail Khan and a diving Shah held an excellent catch at point.
Mohammad Amir then turned 126 for one into 126 for two when Hales (54) edged a seaming delivery from the left-arm quick and Younis Khan held a difficult low chance at second slip.
Root, who made a Test-best 254 in England’s 330-run series-levelling win at Old Trafford, struck two superb fours off Sohail — a back-foot force followed by a cover-drive.
Root, however, had a reprieve on 25 when he edged Rahat Ali only for Mohammad Hafeez to drop the low, two-handed, chance at first slip.
It was tough on left-arm paceman Rahat, who bowled superbly in reeling off five straight maidens in a spell of seven overs for just seven runs.
After lunch, Root pulled Shah for a boundary that saw him to a 108-ball fifty. But Shah, bowling into the rough outside leg stump, had his revenge when Root, not for the first time this season, mistimed a sweep and gave a simple catch to Hafeez at short fine leg.
Vince, yet to make a fifty in nine Test innings, had been composed in equalling his highest score at this level of 42. But he too fell in familiar fashion when, flirting outside off stump against the new ball, he wastefully guided Amir to second slip Younis.
England, 262 for four at tea, lost Ballance (28) on 285 when Shah, bowling round the wicket, had the left-hander well caught by leg slip Asad Shafiq off a genuine glance.
But Ali cover-drove Shah for four and, two balls later, he whipped him for another four wide of mid-on. Bairstow clipped Sohail off his pads and swept Shah for two well-struck fours on his way to a 69-ball fifty.
Left-hander Ali, to chants of ‘Moeen, Moeen Ali’ from a crowd of more than 15,500, followed Bairstow to the landmark in 64 balls.