Danny McGuire's hat-trick broke Harlequins' hearts and sent Leeds Rhinos into the quarters-finals of the Carnegie Challenge Cup after a thriller at The Stoop.
Quins had battled back from 24-4 down to take a 26-24 lead with three minutes remaining but Great Britian captain Jamie Peacock and McGuire spared the Rhinos' blushes with late tries to stun the brave hosts.
The Rhinos went in front in the ninth minute when young full-back Ben Jones-Bishop, deputising for Brent Webb who has been away on international duty with New Zealand, seized on Will Sharp's error and sprinted 70 yards for his first senior try.
Skipper Sinfield added the conversion but Quins hit back 10 minutes later when Tony Clubb muscled his way over from close range.
But the Super League champions were soon back in front when McGuire tricked his way through the Quins defence for an easy try.
Winger Scott Donald gave the visitors an 18-4 half-time lead when he got on the end of Kallum Watkins' brilliant offload to sprint over and Sinfield successfully added his third conversion.
Leeds extended their lead when McGuire crossed for his second try of the afternoon in the 42nd minute but Quins refused to lie down and Danny Orr began the fightback seven minutes later when he scrambled over from close range.
Henry Paul added the extras before the former Wigan and Bradford star reduced the deficit to 24-16 when he converted his own try with 25 minutes remaining.
Paul soon crossed for his second and, when Orr added another after 62 minutes, Quins had scored 22 unanswered points in 18 minutes.
But the world champions responded and were back in front three minutes from time when Peacock powered his way through sloppy defending to crash over.
And McGuire completed his hat-trick and Leeds' win in the dying seconds with another smart finish and captain Sinfield added his sixth goal as his side sneaked through.