Lafay gives Cofidis team first Tour de France victory in 15 years
The Frenchman, who had showed great form in Saturday's opening stage, powered away with one kilometre to go and did not look back with a reduced bunch breathing down his neck.
Cofidis had not won a stage on the Tour since Sylvain Chavanel in Montlucon in 2008.
Belgian Wout van Aert(Jumbo Visma) took second place and Slovenian Tadej Pogacar finished third while his UAE Emirates team mate Adam Yates retained the overall leader's yellow jersey.
Two-time Tour winner Pogacar gained a two-second bonus, added to the eight seconds he earned for being first to the top of the Jaizkibel climb, just ahead of defending champion Jonas Vingegaard.
The Danish rider picked up five seconds there but now trails his big rival by 11 seconds in the overall standings.
Yates leads Pogacar by six seconds, with Vingegaard in sixth place.
Monday's third stage is a 193.5-km ride from Amorebieta Etxano to Bayonne as the race enters France.