Sagan unclipped from his pedal in the final push, but still had enough to hold off the 2016 Olympic road race champion from Belgium.
"Maybe everyone thinks that it was an advantage that Sagan unclipped but because of that I moved to the side and out of his slipstream and then I suffered in the wind!" Van Avermaet said.
"I wanted to surprise Sagan, I hoped he'd start his sprint early. I would come out of his wheel.
"He is one of the best and not many can beat him. All the pieces of the puzzle have to fall into place to do so. I knew it'd be super hard. The day needs to be perfect to beat Sagan."
Van Averment clicked recently and had some perfect days judging by his results. It first came together when the 2015 Tour de France visited Rodez on a fast uphill sprint: Van Avermaet won and Sagan placed second.
Sagan lost to his Belgian rival in Omloop Het Nieuwsblad and Tirreno-Adriatico in 2016. Van Avermaet claimed a Rio de Janeiro gold medal, but Sagan skipped the road race for the mountain bike race.
Their rivalry continued in the Canadian one-day races where Sagan won over Van Avermaet in second in the GP Quebec, before Van Avermaet beat his top rival to second place in the GP Montreal two days later.
This year, 'Golden Greg' has had the upper hand with wins in Omloop Het Nieuwsblad and Ghent-Wevelgem, but the pieces failed to fall into place in Longwy.
Sagan clipped in to his pedal and rocketed ahead. Michael Matthews (Sunweb) placed second, Daniel Martin (Quick-Step Floors) took third and Van Avermaet settled for fourth.
BMC Racing had ridden the final technical kilometres on the front for their general classification hopeful Richie Porte and if things worked out, Van Avermaet for the stage win.
"Richie did a hard job, everyone was a little à bloc. Even Peter had to leave the gap a little bit. Then it was about timing," Van Avermaet added.
"It was actually really good, [the team] kept position for both of us. Richie was well placed and the team did a good job. I was well placed. I think this was the best option to play.
"We had both options to play and the best solution not to lose time. I felt great support from my team."
Some criticised the team for giving all its men for a Van Avermaet win in stage two of 2016. When Porte punctured, he had no support and lost 1-45.
None other than Sagan won that stage, where Van Avermaet took eighth.
Thank you for reading 10 articles this month* Join now for unlimited access
Enjoy your first month for just £1 / $1 / €1
*Read 5 free articles per month without a subscription
Join now for unlimited access
Try first month for just £1 / $1 / €1