The most direct way nationalism caused World War I was through the assassination of Archduke Franz Ferdinand, who was the heir to the throne of the Austro-Hungarian Empire.
Many oppressed Slavic groups in the Austro-Hungarian Empire wanted to form independent nation states. They were tired of having to speak German, having to bow to the supposed superiority of the German culture, and having their own needs subordinated to the needs of the empire. Thus, nationalist movements broke out across the Slavic territories. Among the most militant nationalists were the Serbs. A militant nationalist Serbian group, the Black Hand, assassinated the archduke—when he was on Serbian soil—in protest of their country's continued participation in the Austro-Hungarian empire.
This led, on July 23, 1914, to a series of unconditional demands sent to Serbia by the Austro-Hungarian empire in the form of an ultimatum. Serbia refused to honor the demanding ultimatum.
As a series of alliances between different European countries were already in place, different countries backed either the Austro-Hungarian Empire or Serbia, depending on their allegiances. Russia, France, and England were prepared to use military means in order to support Serbia, while Germany was ready to go war with its ally, the Austro-Hungarian empire. Soon enough, World War I broke out.