Coastal cities, most of them experiencing growing population and rapid urbanization, are facing reactive nitrogen (Nr) pollution crisis and are considered as Nr hotspots worldwide. Increased human activities generate drastic effects on the nitrogen (N) flows of coastal cities. Nevertheless, the N flows of coastal cities are not clearly understood, and the existing city-scale N flow models cannot depict the detailed N flows in coastal cities. Here, we developed a NItrogen MOdel for COastal ciTy (NIMOCOT) which includes four processes and 14 subsystems and used the Material Flow Analysis (MFA) method to model detailed N flows by taking Xiamen as a case study. The results showed that total N inputs to and outputs from Xiamen in 2015 were 403.8 and 201.7 Gg respectively, with half of total N inputs accumulated in the city. The top two N inputs were N embodied in nonfood goods consumption by households and fossil fuel combustion, accounting for 48.5% and 38.5% of total N inputs to Xiamen respectively. After city internal consumption, 109.5 Gg NOx were emitted mainly from energy and industrial subsystems, accounting for 93.2% of total gaseous Nr emissions to the atmosphere. In the typical coastal city, shipping contributed to 34.0% of the total gaseous Nr emissions to the atmosphere in the transportation sector, ranked after highway (58.0%). Moreover, the largest Nr contributor to the hydrosphere came from riparian import (56.0%) which has a significant impact on the hydrosphere of Xiamen. Our results indicated that enhancing the remove ratio of NOx emissions during fossil fuel consumption, and strengthening watershed managements to low riparian N imports from upstream will be useful for reducing N contaminants in environment of Xiamen, and NIMOCOT model is suitable for tracking the key N pollutant sources and could help to make decisions on cutting associate pollutants in coastal cities.