Clinton and Trump were both very unpopular, and while Trump was slightly more unpopular it really made no difference as the swing voters were those who disliked both candidates. Due to the Comey letter they swung to Trump and gave him the win.
Comey letter or not, those undecided voters were largely people who just couldn't quite figure out if they could stomach voting for Trump until the day came and they did.
It's better we deal with the Trump now than 2020. And I'm not talking about Trump specifically; just the right wing populist wave that's acted as a successful alternative to contemporary liberalism for many working class people.