Just 10 minutes earlier, Northampton appeared to have the game in the bag after Lee Dickson had finished off a 50-metre attack to put the Saints 23-15 ahead.
But Ryan Lamb, who kicked everything else all day, missed with his conversion attempt and that left the door ajar for Harlequins - and it was their pack who barged it open.
Nick Evans' sixth penalty took them within striking distance and then, with 76 minutes on the clock, Harlequins captain Chris Robshaw instructed his fly-half to kick the next penalty to touch.
And from the edge of the Northampton 22, the Harlequins pack launched a ferocious lineout drive with Marler touching down in a forest of legs.
Quins had not only driven Saints over their own line but also infield, leaving the victory conversion a formality for Evans.
It was heartbreaking on the day for Northampton, but over the course of the season Harlequins deserve a place in the final having led the Premiership since September 17.
Northampton were forced into a late change when Chris Ashton, who has been struggling with a back injury, was replaced on the Saints wing by Russian international Vasily Artemyev.
The Saints maintain Ashton's injury was not caused by his swallow dive try celebration in the bonus point victory over Worcester last week that sealed Saints place in the semi-finals.
Harlequins were without their own England wing in Ugo Monye and scrum-half Danny Care, whose shoulder injury opened the way for Karl Dickson to start opposite his younger brother Lee.
It was an engaging contest with both men anxious to play at pace but neither side could capitalise on their flashes of early adventure and the game eventually came down to a fly-half kicking duel.
When Lee Dickson refused to return the ball after referee Andrew Small awarded Harlequins a third-minute penalty it prompted a fraternal shoving match.
Northampton were also marched back 10 metres and into range for Evans, who duly kicked his side into an early lead but then missed his second attempt, failing to reward a powerful Harlequins scrum.
Nick Easter was playing as if he had a point to prove to the England management, who left him out of the tour to South Africa, with a series of powerful carries and offloads to keep Harlequins on the front foot.
Northampton were not only battling well but threw some attacking shots of their own, with a scything Ashton-style break from Artemyev.
The Saints edged into the lead with three penalties from Lamb - the second of which from 50 metres just crept over the bar - before Harlequins mounted a period of sustained pressure.
The Samoan flanker Maurie Fa'asavalu was the catalyst with two bulldozing runs into the Saints 22.
Northampton defended their line but were penalised once again for killing the ball, leading to a yellow card for number eight Roger Wilson and Evans drawing the scores level.
Lamb's fourth penalty handed Northampton the half-time advantage and Harlequins were denied what they felt was a legitimate try early in the second period.
After Mike Brown's excellent kick-chase had earned Harlequins a lineout deep in Northampton territory, Jordan Turner-Hall crashed onto the quick throw through the unset Saints defence and over the line.
But referee Small ruled Harlequins could not take the quick throw, brought them back for a regulation lineout and Northampton defended it expertly to win the scrum and clear.
Evans and Lamb exchanged penalties again before the Harlequins fly-half missed a shot at goal after an altercation between Paul Doran-Jones and Marler.
Northampton then slowly began to take control of the game. Lamb's midfield break stretched Harlequins and when Lowe was caught offside, the Saints fly-half landed his sixth penalty to give them an 18-15 lead.
And then came the decisive moment as Northampton opened Harlequins with centres James Downey and George Pisi heavily involved in an attack down the right.
Artemyev took it on before the ball came back inside and Downey supplied the scoring pass to Dickson - but, crucially, Lamb missed the conversion.
Another Evans penalty kept Harlequins' hopes alive and then Robshaw took a bold call. With four minutes remaining he opted to kick a penalty for touch.
The Quins pack rewarded him with a phenomenal lineout drive, shoving Northampton infield, towards their own posts and then over the line.
Marler emerged from the bottom of a pile of bodies claiming a try that was eventually confirmed by the television official Graham Hughes.
The position was key. Evans was left with the simple conversion to seal victory.