Cardiff Blues battled to a Heineken Cup quarter-final with a compelling win over Racing Metro.
But they travel to holders Leinster in the last eight after finishing second in Pool Two to Edinburgh, who secured a bonus-point win over London Irish.
Lloyd Williams and Alex Cuthbert (twice) went over for the hosts and Leigh Halfpenny did the rest, but they fell short of a bonus-point try.
Josh Matavesi and Sereli Bobo crossed for Racing's tries.
Jonathan Wisniewski, Sebastien Descons and Frans Steyn contributed 20 points between them with the boot.
Munster v Ulster
Leinster v Blues
Edinburgh v Toulouse
Saracens v Clermont Auvergne
Matches to be played 6/7/8 April
Cardiff Blues were forced into a late change as hooker Rhys Thomas fell victim to a stomach illness to make way for Ryan Tyrell, with Marc Breeze coming on to the bench.
The home side were also without centre Jamie Roberts (knee) and preferred Gavin Evans to Gavin Henson as Casey Laulala's midfield partner.
Laulala was a regular threat in attack, but the Blues' first-half scoring efforts owed more to opportunism than creativity.
Visiting fly-half Wisniewski kicked an early penalty, but Steyn was overly relaxed before scrum-half Williams charged down his clearance to gather and score the opening try after seven minutes.
Halfpenny converted before he and Wisniewski exchanged penalties, but the hosts fell behind as Steyn launched a wonderful move that ended with full-back Matavesi going over in the corner.
Scrum-half Descons and Halfpenny continued the kicking duel with a shot each at goal.
Cuthbert then caused consternation in Racing's ranks with what looked suspiciously like a knock-on before he grasped the ball and beat the remaining defence for Halfpenny to convert.
But the attacking threat of the visitors that Blues joint head coach Gareth Baber spoke of in the build-up reared its head as wing Bobo finished off in style before Descons put the visitors ahead with the conversion.
Despite his absence the Blues' scrum forced a penalty which Halfpenny again landed but Steyn brought down the curtain on the opening period with a shot from inside his own half that gave the French club a 24-23 half-time lead.
The second period opened with another Cuthbert try - this time without controversy - as Racing failed to deal with Dan Parks' lofted kick and the towering wing, a member of the Wales squad, again gathered to race free.
Halfpenny converted from the touchline and he and Descons again exchanged penalties before Steyn banged over a second huge kick from inside his own half to leave the contest finely balanced.
Munster or Ulster v Edinburgh or Toulouse
Saracens or Clermont Auvergne v Leinster or Cardiff Blues
Matches to be played 27/28/29 April
Matavesi's hesitation ended with a failed drop-goal attempt and as the clock ticked down Halfpenny put over a close-range penalty following a Ma'ama Molitika drive.
Fortune favoured the hosts when Parks' kick went into touch via Jacques Cronje's chin. From the line-out Xavier Rush broke through only for Richie Rees to be held up inches short of the line.
With Edinburgh having scored a bonus-point try the Blues needed to match them to earn a home quarter-final, but they were unable to take two late chances, twice failing to secure their own throw on close-range attacking line-outs.
As a result, instead of hosting Clermont Auvergne in the last eight, they face a daunting trip to Dublin to face Leinster.
Cardiff Blues coach Gareth Baber:
"We are absolutely over the moon to be in the quarter-final of the European Cup.
"We targeted being in it, and we have fulfilled our target. This competition throughout the whole weekend has thrown up little scenarios.
"Hats off to Edinburgh, they got their four tries today. We scored three, and it was always going to be as close as that."
Leigh Halfpenny; Alex Cuthbert, Casey Laulala, Gavin Evans, Chris Czekaj; Dan Parks, Lloyd Williams; Gethin Jenkins, Ryan Tyrell, Scott Andrews, Bradley Davies, Paul Tito (capt), Michael Paterson, Xavier Rush, Sam Warburton.
T James for Czekaj (67), R Rees for L Williams (53), J Yapp for G Jenkins (36), Hobbs for Andrews (42), Molitika for Tito (70).
M Breeze, J Navidi, C Sweeney.
Racing Metro 92:
J Matavesi; H Chavancy, F Steyn, F Estebanez, S Bobo; J Wisniewski, S Descons; M Tuugahala, B Noirot, B Sa, K Ghezal, F van der Merwe, J Leo'o, A Batut, S Chabal.
G Arganese (for Noirot, 54), E Ben Arous (for Tuugahala, 45), J Orlandi (for Sa, 54) J Nailiko (for van der Merwe, 50), J Imhoff (for Wisniewski, 24), J Cronje (for Chabal, 52).
This page is best viewed in an up-to-date web browser with style sheets (CSS) enabled. While you will be able to view the content of this page in your current browser, you will not be able to get the full visual experience. Please consider upgrading your browser software or enabling style sheets (CSS) if you are able to do so.