Sri Lanka were 214 for four in their second innings at stumps on third day with a lead of 106 runs.
Jayawardene was batting on 55 and Sri Lanka captain Angelo Mathews 24 not out, with two days remaining to decide the fate of this two-match series following the drawn first Test at Lord`s.
Off-spinner Ali, primarily a batsman and in just his second Test, stunned Sri Lanka with two wickets for no runs in three balls to dismiss Kumar Sangakkara and Lahiru Thirimanne.
Earlier, Mathews took his Test-best figures of four for 44, with fellow seamer Shaminda Eranga enjoying a return of four for 93 as England — 320 for six overnight on the back of Australia-born opener Sam Robson`s maiden Test century — were bowled out for 365.
The pick of the four England wickets that fell Sunday came when all-rounder Mathews produced a superb off-cutter to clean bowl tailender Liam Plunkett.
England`s seamers then repeatedly bowled too short. And when James Anderson did induce an edge from Dimuth Karunaratne, then on four, second slip Chris Jordan dropped the catch.
It took fast bowler Plunkett, who in the first innings had taken a Test-best five for 64 on his Yorkshire home ground, to make the breakthrough England so badly needed when he had Kaushal Silva (13) caught behind off a full-length delivery.
New batsman Sangakkara was quickly into his stride, going down on one knee to drive Plunkett through the covers for a boundary. Karunaratne`s erratic innings came to an end when, on 45, he gloved Plunkett down the legside to wicketkeeper Matt Prior.
The batsman reviewed New Zealand umpire Billy Bowden`s decision but replays confirmed he was out, having faced 51 balls with three boundaries.
Left-hander Sangakkara struck two stylish boundaries off Anderson, straight down the group and a whip through mid-wicket, to become only the fourth batsman to score fifties in seven successive Test innings after West Indies greats Everton Weekes and Shivnarine Chanderpaul and Zimbabwe`s Andy Flower.
However, Ali did for Sangakkara when the batsman played down the wrong line and was lbw for 55. Sangakkara reviewed the decision but, with replays confirming his dismissal, it was the end of a 103-ball innings including six fours and a stand of 79 with Jayawardene.
Ali then struck again when he bowled Thirimanne for his second nought of the match with a superb delivery that drifted in towards middle-and-leg and then turned past the outside edge to hit the left-hander`s middle stump.
That meant Sri Lanka vice-captain Thirimanne had scored just four runs in four innings this series. But Jayawardene was still there, while Mathews had made a hundred at Lord`s.
Jayawardene`s single off Ali then saw the veteran right-hander to a 103-ball fifty including five fours.
Mathews then edged Jordan to give Sri Lanka a lead of a hundred before next ball driving him through the offside for an emphatic boundary.