The fans who have stood and cheered at the end of Lin-Manuel Miranda’s masterpiece “Hamilton” may not fully realize it, but they are hailing the life and the work of one of the greatest nationalists in American history.

The word “nationalism” has a pejorative connotation, especially when mixed up with the negative feelings around Donald Trump. This assumption that nationalism must be a malign force is lazy and thoughtless, as demonstrated by Alexander Hamilton’s much celebrated career.

At its most basic, nationalism is the idea that a distinct people, set apart by their common history and culture, should be self-governing.

In the American context, it has meant asserting and protecting our sovereign rights as a nation, creating a strong and capable national government, building a formidable military, expanding across the continent and excluding potentially hostile foreign powers from our immediate vicinity. It also has insisted that the nation have a strong cultural core.

Hamilton advanced and, to a significant extent, defined these nationalist projects. The most important was the first — establishing our independence from the British empire in the world’s greatest nationalist rebellion. The American Revolution became an inspiration for peoples yearning to govern themselves around the world and established the principle that government exists to serve the people, not the other way around.

After serving as a crucial adjutant to George Washington during the Revolution, Hamilton took a leading role in the next nationalist undertaking: dumping the Articles of Confederation to create a sound and durable national government. He was a prime mover behind the Constitutional Convention, and wrote roughly two-thirds of the Federalist Papers, making the case for the convention’s inspired work.

Then, Hamilton helped put the new national government on a firm financial foundation. He successfully pushed the federal government to fund the national debt and assume the war debts of the states. He advocated tariffs to bolster the manufacturing sector, and he convinced President Washington to back the creation of a national bank — all toward the goal of becoming a nation as formidable as Great Britain.

Hamilton believed, as the historian Craig L. Symonds puts it, that the country required “all the accoutrements of world power: a vital domestic industry, a healthy world trade and, to protect that trade and the national integrity, a naval fleet.”

As Hamilton wrote in his rousing finale of Federalist 11, “Let the thirteen States, bound together in a strict and indissoluble Union, concur in erecting one great American system, superior to the control of all transatlantic force or influence, and able to dictate the terms of the connection between the old and the new world!”

It’s fashionable now on both the left and the right to say that America isn’t so much a nation as an idea. This would have been a nonsensical statement to Hamilton and the other Founders. He believed that our institutions, our power and our culture mattered a great deal. An immigrant himself, he worried nonetheless that unchecked immigration might threaten our cultural core.

In a pseudonymous newspaper essay in 1802, he wrote, “The safety of a republic depends essentially on the energy of a common national sentiment; on a uniformity of principles and habits; on the exemption of the citizens from foreign bias and prejudice; and on that love of country which will almost invariably be found to be closely connected with birth, education and family.”

Today, love of country is a dwindling asset. The left tends to view America as rotten to its core. Millennials are notably less attached to the symbols of the American nation — and less drawn to patriotic pride — than their elders. Hamilton, surely, would view this as a desecration of what he created.

America is powerful and free, in part, because Hamilton’s nationalizing program was so influential and successful. By all means honor (and celebrate in song), Hamilton’s brilliance and passion, his farsightedness and determination, but no account of him, or our country, can be complete without recognizing his all-important nationalism.

Rich Lowry is the author of “The Case for Nationalism: How It Made Us Powerful, United, and Free” (Harper Collins), out Tuesday.