Seamer Mahmood claimed two early wickets as Yorkshire slipped to 92-4, still 258 runs behind, but the visitors resisted until deep into a thrilling evening session.
Mahmood returned to strike twice more and leg-spinner Parkinson claimed the winning wicket when Dom Bess was caught at slip with 40 balls remaining.
Lancashire’s win by an innings and 79 runs keeps them top of Group Three and ensures they have the only unbeaten record in county cricket after four wins in seven games.
They are 26 points clear of Northamptonshire in third place, with Yorkshire only two points clear of the Wantage Road side.
Skilful Mahmood was brilliant at either end of the day on an abrasive pitch.
Harry Brook top-scored with 52 for Yorkshire and Bess 46.
This was Lancashire’s first Roses Championship win at Old Trafford since 2000 and first at any venue since 2011.
Parkinson’s leg-spin was likely to be the chief threat, but Mahmood finished with five for 47 from 26 overs.
He ousted Will Fraine and nightwatchman Steve Patterson. Fraine’s middle stump was uprooted by an in-swinger before Patterson lost his off stump with one that moved away.
Mahmood bowled an opening seven-over spell of two for two before fifth-wicket pair Brook and George Hill started the fightback by sharing 59 in 27 overs through the majority of the morning.
Tom Bailey bowled Hill for 18 as the score fell to 151-5 in the 81st over, the second of the afternoon and the first with the new ball.
Brook reached his fifth fifty of the campaign off 104 balls, only to fall lbw as Parkinson struck him on the boot, leaving the score 180-6 after 93 overs – a minimum of 50 remaining.
Bess was handed a life on 17 by Liam Livingstone at slip off Parkinson with 45 overs remaining.
The off-spinner shared 58 in 28 overs with wicketkeeper Harry Duke either side of tea before the latter shouldered arms and was bowled by Luke Wood for 29 – 238-7 with 22 remaining.
Mahmood returned to get Jordan Thompson and Ben Coad caught behind in successive overs - Yorkshire 271-9 with 7.3 overs remaining - before Parkinson had Bess caught at slip by Livingstone to spark jubilant scenes.
Yorkshire’s first defeat came as the last three wickets fell for no runs.
Support The Yorkshire Post and become a subscriber today. Your subscription will help us to continue to bring quality news to the people of Yorkshire. In return, you’ll see fewer ads on site, get free access to our app and receive exclusive members-only offers. Click HERE to subscribe.