Joris Segonds kicked a last-gasp penalty as 14-man Stade Francais claimed a place in the last 16 of the Champions Cup with a remarkable 37-31 win over Connacht.
Stade needed a bonus-point win with a margin of at least six points to replace Cardiff in eighth in Pool B.
The French side's spot was confirmed when Wasps were beaten 45-7 in Sunday's later game.
Connacht, who were already through, finish the group stage in fifth.
When Jarrad Butler ran in the province's fourth try in the 61st minute, Stade's faint hopes of a top-eight finish appeared over.
They had already been reduced to 14 when hooker Tolu Latu was shown a second yellow card for swearing at referee Wayne Barnes seven minutes into the second half.
Butler's converted score extended Connacht's lead to 11, but tries from Ryan Chapuis and Adrien Lapegue either side of Conor Oliver's yellow card incredibly put Stade ahead by three points.
They needed at least a six-point margin to leapfrog Cardiff on goal difference and, after Segonds saw an 80th-minute penalty from halfway come off the post, he was given a second, more straightforward chance. It came after Connacht were pinged for obstruction in their own 22, and he made no mistake.
Hosts come out on top in helter-skelter contest
Connacht arrived in Paris assured of their place in the next round after Cardiff were awarded a 28-0 walkover victory against Covid-hit Toulouse.
For the second week in a row the western province let a multiple score lead slip in the second half having played some inspired rugby in the opening hour.
They were the better side in the first half and went ahead through Alex Wootton after just seven minutes before Lepegue responded for the hosts with a brilliant training-ground try.
Both sides then had fantastic scores ruled out, with Stade front row Latu being sent to the sin-bin for a dangerous and unnecessary clearout that chalked off Leo Barre's excellent score.
Stade had little choice but continue to throw caution to the wind despite of being a man light, and responded to Caolin Blade's try with a score of their own from Ngani Laumape two minutes into the second half.
Latu's permanent dismissal, just two minutes after coming back on from his sin-bin, was almost immediately compounded by Tom Farrell crossing for Connacht's third try as the game began to turn in favour of the visitors.
But Stade kept coming, responding again through Kylan Hamdaoui before Butler used the additional space in Stade's defensive line to romp through for the bonus-point try.
Oliver's yellow card for persistent infringements as Connacht tried in vain to stifle the attack that led to Chapuis' 69th-minute try, brought the hosts back to numerical parity. When Segonds converted Lapegue's second excellent score the Top 14 side sniffed a turnaround.
The final three points were delivered in a fashion befitting of a dramatic game, when Segonds' initial penalty came off the post. Connacht sought to escape their 22 through Mack Hansen but Butler was pinged for illegal blocking, allowing the replacement fly-half to kick the all-important penalty.
Stade Francais: Hamdaoui; Veainu, Laumape, Barre, Lapegue; Sanchez, Percillier; Castets, Latu, P Alo-Emile; De Giovanni, Gabrillagues; Francoz, Chapuis, Gray (capt).
Replacements: Da Silva, M Alo Emile, Roelofse, Van der Mescht, Kremer, Hall, Segonds, Champ
Connacht: O'Halloran; Wootton, Farrell, Arnold, Hansen; Carty (capt), Blade; Duggan, Delahunt, McGrath; Dowling, Murray; Prendergast, Oliver, Butler
Replacements: Heffernan, Ward, Illo, Leva Fifita, Boyle, Reilly, Fitzgerald, Kilgallen