Super League strugglers Catalans Dragons survived a tremendous effort from part-timers York to secure their place in the sixth round of the Ladbrokes Challenge Cup.
The French club, who are bottom of Super League with just two wins from 11 matches, were rattled for long periods by opponents from two divisions below and needed late tries from Jodie Broughton and Greg Bird to finally wrap up a 34-22 victory.
The City Knights, who went into the fifth-round tie on the back of a seven-match winning run, were humiliated 92-2 in their last meeting with the French club in Perpignan five years ago but this time pushed them all the way in an entertaining tie.
York stand-off Connor Robinson was arguably the best player on the pitch while two tries in seven minutes from substitute forward Joe Porter brought the 3,081 crowd at Bootham Crescent to its feet and threatened to inspire a famous victory.
Yet it looked fairly routine for the Super League team when they opened up a 10-0 lead inside the first quarter.
Stand-off Samisoni Langi and centre Vincent Duport combined to get winger Fouad Yaha over for a simply-worked try at the corner while loose forward Jason Baitieri took the more direct route to barge his way over by the posts.
Lucas Albert added one conversion and the Dragons might have been further in front but for referee Chris Kendall ruling centre Tony Gigot offside when he touched down Albert's grubber kick.
James Ford's men were far from overawed, however, and they struck back in sensational fashion with Porter's brace of touchdowns.
His first effort was set up by an audacious one-on-one ball steal by diminutive winger Judah Mazive on Yaha which epitomised his team's spirited approach.
Robinson saw his first conversion attempt bounce back off an upright but his second levelled the scores and threatened a major upset.
However, the Catalans struck a decisive blow on the stroke of half-time when substitute prop Mickael Simon barged his way over for a third try and Albert kicked his second goal to make it 16-10.
That became 22-10 five minutes into the second half when full-back David Mead put Albert through a gap for the visitors' fourth try, but still the Knights came back.
The part-timers were not afraid to throw the ball around and full-back Kieren Moss finished off another impressive flowing move by taking Sam Scott's pass by his boot laces to score his side's third try.
It might have been all square once more when stand-off Ben Cockayne re-gathered his own kick over the Dragons defence but Gigot pulled off a timely interception and the Catalans took the opportunity to re-establish a two-score lead on the hour with a penalty from Albert.
Aided by a string of penalties, the Catalans then secured victory with Gigot sending Broughton over at the corner and Bird crashing through for their sixth try, although York had the final say when highly-rated second-rower Joe Batchelor swooped on a loose ball for a consolation try.