The left-arm spinner combined with wicket-keeper Geraint Jones to get rid of dangermen Upul Tharanga (52) and Kumar Sangakkara (65) in what was the 24-year-old bowler's home Test debut.
At stumps on the third day Sri Lanka, following on, were 183 for three, still 176 runs behind England's imposing first innings 551 for six declared.
Sri Lanka captain Mahela Jayawardene, who'd top scored in the first innings with 61, was 35 not out and Farveez Maharoof, the nightwatchman, unbeaten on five.
Tharanga and Sangakkara restored some pride for Sri Lanka with a partnership of 109 which rescued their side from the depths of 10 for one.
The left-handers' stand was timely with former captain Sanath Jayasuriya announcing he was ready to end his Test retirement, watching from the boundary.
Their combined effort was a Sri Lankan record for the second-wicket against England, surpassing the 92 shared by Marvan Atapattu and Sangakkara at Galle in 2000-01.
At tea, Sri Lanka were 93 for one, with Tharanga on 41 and Sangakkara 30.
Tharanga went to his third Test fifty with a sweetly-timed cover-driven four off England captain Andrew Flintoff, his seventh boundary in 115 balls also securing the century stand.
Panesar, the first Sikh to play Test cricket for England, cramped Tharanga with a turning delivery and Jones did the rest to leave Sri Lanka 119 for two.
Sangakkara, batting watchfully, then completed his fifty with a single off the Northamptonshire slow bowler before he too was caught behind, having batted for nearly four hours.
Panesar was then unlucky not to dismiss nightwatchman Maharoof for nought after Flintoff appeared to take a clean catch at silly point. But Pakistani umpire Aleem Dar rejected England's appeals.
Earlier, Matthew Hoggard took his 200th Test wicket as Sri Lanka were bowled out for 192 in their first innings - 160 runs shy of the follow-on target of 352.
Hoggard, who finished with first innings figures of four for 27, soon struck again.
The often under-rated 29-year-old Yorkshireman, known for his ability to swing the ball into left-handers, brought one back to Jehan Mubarak and the batsman, late on a drive, was bowled off an inside edge for six.
Sri Lanka started Saturday in the dire position of 91 for six and only stands of 44 and 61, for the seventh and ninth wickets respectively, took them to three figures.
Jayawardene resumed on 40 not out.
No Sri Lankan had made a fifty in the preceding fixture, a 10-wicket defeat against England A.
However, Jayawardene's seventh boundary, a cut off 24-year-old debutant quick Sajid Mahmood, who'd rocked Sri Lanka with a spell of three wickets for no runs in nine balls Friday, took him to the landmark.
Maharoof supported his skipper well before he was caught and bowled for 22, after trying to turn the ball legside to give Hoggard his landmark dismissal.
Hoggard was the tenth England bowler to take 200 Test wickets.
And eight balls later Jayawardene's defiant knock ended when he was caught behind off a rising Flintoff delivery for 61, Sri Lanka 131 for eight.
England's total, their highest score against Sri Lanka, was built around hundreds from Kevin Pietersen (158) and opener Trescothick (106) while Cook, on his home Test debut, made 89 and all-rounder Paul Collingwood 57.