They're not opposed. Nationalism just has the tendency of galvanizing a population's support, which can easily bolster an autocracy that represents the "national identity". It's sort of the supporting character for autocracy and related political systems. (I'm just basing this on opinion, not political theory)
It's sort of like gimbal lock: when a particular social movement becomes so pervasive and powerful the mechanisms of government become dangerously aligned and you lose the ability of the political system to perform an important function, namely defend itself and minorities from the tyranny of the majority. Remember, part of the design of separation of powers is that institutions must retain the ability and motivation to compete for power. If the motivation is gone the ability becomes at risk--either by atrophy or by one institution making power grabs that go unchallenged by others institutions or by the people. Discord is, to an extent, a feature, not a bug.
Hugo Chavez was a nationalist that was popularly and fairly elected multiple times until, eventually, the elections weren't actually fair anymore and the institutions of government were irreparably corrupt.
Nationalist movements aren't the only the way this can naturally occur, but it's perhaps the most common in the past two centuries.
Your comment reminds me of Machiavelli’s work “Discourses on Livy” in which he writes, among other things, that discord (between the nobility and the common people) produced the liberty enjoyed by the Roman Republic. Machiavelli’s views on republicanism are very insightful, in my opinion, and offer an understanding of democratic government that may be more prospective of being actualized than what appears to be proposed in much of today’s discourse on democracy.
By the way, I came across one of your HN comments in the past (https://news.ycombinator.com/item?id=18127353) and immediately was impressed by your thinking. Ever since, I look forward to seeing your comments on HN. If you are interested, I would be greatly interested in hearing more of your thoughts expressed in the aforementioned comment of yours. My email is njrc900[at]gmail[dot]com