By the early 1900s, globalization and imperialism had created cosmopolitan cities such as the Chinese treaty port of Shanghai, where foreign minorities lived side by side. The outbreak of the First World War put enormous pressure on these multiethnic urban societies. By exploring how the war altered the cohabitation of Westerners in Shanghai, this article connects with current debates on the mechanisms of longdistance nationalism and cosmopolitanism as well as on the importation of conflict in diaspora communities. The many imperial diasporas of Shanghai mostly lived in the French- and British-controlled territories, where the balance of power was renegotiated during the war. Analyzing local community newspapers and diplomatic archives, this article explains why nationalism superseded the shared feeling of cosmopolitanism that prevailed before the war. The cosmopolitan tradition and political complexity clearly delayed the arrival of the war at Shanghai, but could not prevent the process.