At stumps, Pakistan were 340 for six, 12 runs in front, with Younis ending a run of low scores with 101 not out after sharing a fourth-wicket partnership of exactly 150 with Shafiq (109).
This was Younis’s 32nd century in 108 Tests. It was also the 30th successive occasion that Younis had converted a Test innings of 90 plus into a hundred — one more than Australia’s Don Bradman, widely regarded as cricket’s greatest batsman.
Sarfraz Ahmed was 17 not out as Pakistan fought to level the four-match series at 2-2. Earlier, Shafiq put the pain of a pair last time out behind him in style.
Promoted up the order from number six, Shafiq’s century came immediately after he twice made nought during England’s 141-run win in the third Test at Edgbaston.
On Thursday, Pakistan — whose close catching has let them down throughout the series — dropped Moeen Ali on nine and then saw him make 108 in a total of 328.
Shafiq, 30, was dropped off a far harder slip chance by James Anderson on seven — the toughest of the three chances England missed Friday.
Hanif tribute
His innings was all the more poignant as flags above The Oval pavilion were flying at half-mast in honour of Pakistan legend Hanif Mohammad, who died aged 81 on Thursday.
One of cricket’s greatest batsmen, Mohammad had said the equally diminutive Shafiq’s technique was as close as anyone had come to his own. Pakistan resumed Friday on three for one. Azhar, promoted to open after his century at Edgbaston, and Yasir Shah were both nought not out.
But having done his nightwatchman duty by getting through the first hour, Shah fell for 26 when he nicked fast bowler Steven Finn to second slip Joe Root.
The blue and sunny skies above The Oval, allied to a good pitch, offered some of the best batting conditions this series.
Shafiq avoided a third straight nought by getting off the mark with a cover-driven four off Finn.
Finn put down a caught and bowled chance from Azhar, then on 35, before the batsman was caught behind on 49 gloving a sweep off Ali.
But Shafiq and Younis both lofted off-spinner Ali for huge straight sixes over long-on.
Younis, who had been hopping about the crease during a series where his previous best score was 33 in Pakistan’s win in the first Test at Lord’s, looked far more in control on Friday. His square-cut four off Anderson saw him to an 86-ball fifty in two hours.
Shafiq spent 17 balls on 99 before a quick single took him to a hundred in just over five hours off 164 balls with 12 fours and two sixes.
Unlike previous Pakistan hundreds this season, Shafiq opted against celebrating with a flamboyant press-up routine — a tribute to the military staff who had helped the squad get fit during a pre-tour boot camp.
Shafiq was out soon afterwards when a pull off Finn was brilliantly caught by Stuart Broad, diving to his left at short mid-wicket.
Woakes then struck twice in an over with the new ball to remove skipper Misbah-ul-Haq and debutant Iftikhar Ahmed.
Younis, 38, got to his hundred in 139 balls with 15 fours and a six. The conductor of Pakistan’s victory press-up celebrations across London at Lord’s, Younis marked his century more modestly by kissing the Oval turf.
Earlier in the tour, Younis had said he would be the “happy man of the earth” if he could play well in a Pakistan series win.
The series victory might be beyond Pakistan now, but Younis had plenty of reason for rejoicing on Friday.