It was in large part due to the French Revolution and Napoleonic Wars. 

First, France had a revolution that led to the composition of the national anthem, [La Marseillaise,][1] that started *French* national feeling.

Napoleon's invasion of Germany, and the [creation of the Conferation of the Rhine][2] consolidated a bunch of "church" holdings into far fewer "states" that later formed the basis of German nationalism.

The creation of the Duchy of Warsaw led to a (temporary) resurgence of Polish nationalism.

The invasion of Russia and ultimate defeat of Napoleon stirred up Russian national feeling, as outlined in "War and Peace. To perhaps a lesser extent, this was true in Austria and Prussia as well.

Napoleon's invasion of Italy supported the continued consolidation of much of that country in a few power blocs (e.g. the Papal States, Naples-Sicily, etc.), mostly united against the "outsider."

[1]:https://history.stackexchange.com/questions/14667/when-was-the-first-national-anthem/14670#14670
[2]:https://en.wikipedia.org/wiki/Confederation_of_the_Rhine