At stumps, on the second day, Sri Lanka had collapsed to 91 for six, still a huge 460 behind England's first innings 551 for six declared and needing a further 261 to avoid the follow-on target of 352.
Mahmood, a 24-year-old Lancashire fast bowler, took three wickets for no runs in nine balls to end the day with figures of 5-2-9-3.
Sri Lanka captain Mahela Jayawardene, dropped by diving wicket-keeper Geraint Jones on 34, was 40 not out and Farveez Maharoof unbeaten on six at stumps.
Earlier, Kevin Pietersen scored 158 to equal his Test-best score in what was England's highest total against Sri Lanka, a stand of 173 with Paul Collingwood (57) the centrepiece of the innings.
"I'm not going to say it was the same circumstances but the way I played, I think that was probably my best innings for England in Test cricket," Pietersen told reporters after equalling his Ashes-clinching mark against Australia at The Oval in September.
"Instead of going out and spraying it to all parts at the start, I thought I cultivated a pretty good, sensible, innings," added Pietersen, who proved to his critics he could apply himself by batting for five hours.
"If I keep getting 158 and The Oval stat is a career-best, I won't mind."
The 25-year-old was also full of praise for Mahmood, who became the latest of several recent England debutants to make an instant impact at Test level.
"It was fantastic to see him reverse-swinging the ball at 90mph. Now there is that depth. England can select from 16-20 players instead of 11-12."
After Matthew Hoggard had struck a couple of early blows, Mahmood - the cousin of British boxing star Amir Khan - delivered some knockout punches of his own, breaking the 90mph barrier and bowling with a venom way beyond anything the Sri Lankan quicks had managed.
Jehan Mubarak had been drafted in as an opener for Sri Lanka after Michael Vandort had made a pair in last week's 10-wicket defeat by England A.
However, Mubarak fell for nought, lbw to Hoggard's inswinging seventh ball as Sri Lanka lost their first wicket without a run on the board.
Fellow left-handed opener Upul Tharanga (10) exited in similar fashion, his dismissal made worse by the fact he was shouldering arms.
Hoggard had taken two wickets for seven runs in 18 balls to take his Test tally to 199.
Kumar Sangakkara and Jayawardene, Sri Lanka's two most experienced batsmen, staunched the flow with a stand of 60.
But Sangakkara went for 21 when, driving loosely outside off-stump against Mahmood, he was caught by first slip Marcus Trescothick to give the bowler his first Test wicket with only his 12th ball.
Mahmood, then had Thilan Samaraweera plumb lbw for none before Tillakaratne Dilshan also went for nought after he was run-out.
And when debutant Chamara Kapugedera then fell for a first-ball nought, also lbw to Mahmood, Sri Lanka had lost four wickets for four runs in 21 balls.
Earlier Pietersen's hundred was his third Test century and his first at Lord's as England surpassed their previous best against Sri Lanka of 545 at Edgbaston in 2002.
Muttiah Muralitharan was one of three bowlers who conceded more than 100 runs, taking three for 158 in 48 overs in what was the off-spinner's first Test at Lord's.
Pietersen was eventually lbw to left-arm quick Chaminda Vaas having faced 205 balls with two sixes and 19 fours after being 'caught' off a Maharoof no-ball for 52 on Thursday.
England captain Andrew Flintoff, leading the team in the absence of the injured Michael Vaughan, scored 33 not out at better than a run-a-ball and, shortly before tea, after striking former Lancashire team-mate Murali for six, he declared.
England resumed Friday on 318 for three after Trescothick had made 106 and Alastair Cook, 89.
Scoreboard: England 1st Innings (overnight 318-3)
Fall of wickets: 1-86, 2-213, 3-312, 4-329, 5-502, 6-502
Did not bat: L Plunkett, S Mahmood, M Panesar
Sri Lanka 1st Innings:
Fall of wickets: 1-0, 2-21, 3-81, 4-81, 5-85, 6-85
To bat: C Vaas, N Kulasekara, M Muralitharan
Umpires: Aleem Dar (PAK) and Rudi Koertzen (RSA), TV umpire: Nigel Llong (ENG)
Match referee: Alan Hurst (AUS)