Ross Moriarty’s late try kept Wales’ World Cup dreams alive as they beat 14-man France 20-19 in Oita.
France struck with three first-half tries - through Sebastien Vahaamahina, Charles Ollivon and Virimi Vakatawa - as Aaron Wainwright kept Wales in the tie.
Moriarty was sin-binned moments after coming onto the pitch as a substitute, but it was Vahaamahina’s second-half red card which proved pivotal.
And Moriarty went from zero to hero with a 73rd-minute try, converted by Dan Biggar, to squeeze Wales into the World Cup semi-finals just as their hopes had started to fade.
France took a surprising lead in the fifth minute when second row Vahaamahina pressed through a Wales defence after concerted pressure from a ruck.
The resulting conversion, from Romain Ntamack, came back off the post but Jacques Brunel’s side were buoyed by their start and had a second try shortly after.
Just three minutes after the first, flanker Ollivon completed a fine move involving Virimi Vakatawa, Ntamack and Antoine Dupont - with the latter feeding Ollivon who scored under the posts to give France a 12-0 lead.
Wales were handed a lifeline when Wainwright seized upon a loose ball and suddenly found himself with a clean run on goal. He scored, Biggar converted and when the latter converted a penalty in the 21st minute, the deficit was just two points.
But Gatland was forced into a game-changing substitution on 28 minutes, with Josh Navidi forced off and replaced by Moriarty - who was sin-binned within 90 seconds for connecting with Gael Fickou’s chin when tackling.
Minutes later, France had stretched their lead back to nine points. Seizing upon the momentum and open space offered by Moriarty’s booking, Virimi Vakatawa scored after they dragged Wales across from the lineout.
It was Ntameck who had the two best opportunities to score as the Welsh held on - he released Fickou but a last-gasp George North tackle halted him, before the fly-half’s penalty attempt came off the face of the post to leave France ahead at the break.
Camile Lopez came off the bench at half-time and immediately threatened to extend the lead with a drop-goal attempt which was dragged just wide.
Wales appeared fortunate to be handed a reprieve for a high arm in the ruck after an extended period of pressure from France, but replays revealed Vahaamahina fiercely drove his elbow into Wainwright’s face and he was duly sent off nine minutes after the break.
Biggar helped reduce the deficit to six points with a penalty in the 54th minute, but their opponents were resilient and apt with their game management as the match entered the final 15 minutes.
Wales’ hopes looked to be fading but it was Moriarty who made the game-changing contribution - this time for the right reasons. With time ticking down, and Wales generating momentum from seemingly nowhere, he got the important try - converted by Biggar - to ensure it will be Gatland’s men in the next round.
Featured from our writers
Yahoo Sport UK presents: Tailgate