The early breakaway had featured Roubaix debutant Marc Soler (Movistar Team) and Jelle Wallays (Lotto Soudal), and it was gradually whittled down as the cobbles took their toll.
Quick-Step Floors produced concerted attacks through Zdeněk Štybar and Philippe Gilbert inside the final 100km as they sought to continue their Spring dominance.
After Sagan's attack there was some hesitation in the chase group, just as there had been at the Tour of Flanders when Terpstra attacked - but this time it was Sagan who had taken the initiative and produced what proved to be the decisive move.
Dillier and Wallays were joined at the front of the race by Sagan inside 50km to go.
Another crash brought down Luke Rowe (Team Sky) and Team Katusha Alpecin pair Alexander Kristoff and Tony Martin, ending their hopes of victory. Martin in particular had been animating the race.
The gap closed slightly but then grew again, and Dillier and Sagan's advantage was still a minute with two kilometres to go, and they had time to engage in a bit of cat-and-mouse in the velodrome.
Sagan patiently sat on Dillier's wheel and when he attacked around the final bend. Dillier responded but never looked likely to overhaul the Slovak. It was richly deserved victory for the triple world champion.
Sagan said: "It's amazing, I'm so tired after winning this race ... I just saved energy and did one step forward, I attacked, and I kept going until the finish. I'm very happy and I have to say thank you to all my team-mates because they did a great job."
In the post-race press conference Dillier said: "With Peter it’s like he’s the angel and the devil in the same person. I was happy he’s an angel, because he was working with me.
"He’s the devil because to go in a man-to-man sprint for the finish line, he’s hard to beat. So at the end I was really happy we worked well together, we respected each other, we did a nice sprint in the velodrome and he was better. So congratulations to him."