Retired Lt. Gen. Michael Flynn, who is reportedly being vetted by Donald Trump as a potential running mate, was fired as head of the ­Defense Intelligence Agency (DIA) in the winter of 2014 after three decades in the military. Here he tells the real story of his departure from his post and why America is not getting any closer to winning the war on terror.

Two years ago, I was called into a meeting with the undersecretary of defense for intelligence and the director of national intelligence, and after some “niceties,” I was told by the USDI that I was being let go from DIA. It was definitely an uncomfortable moment (I suspect more for them than me).

I asked the DNI (Gen. James Clapper) if my leadership of the agency was in question and he said it was not; had it been, he said, they would have relieved me on the spot.

I knew then it had more to do with the stand I took on radical Islamism and the expansion of al Qaeda and its associated movements. I felt the intel system was way too politicized, especially in the Defense Department. After being fired, I left the meeting thinking, “Here we are in the middle of a war, I had a significant amount of combat experience (nearly five years) against this determined enemy on the battlefield and served at senior levels, and here it was, the bureaucracy was letting me go.” Amazing.

At the time, I was working very hard to change the culture of DIA from one overly focused on Washington, DC, to a culture that focused on our forward-based war fighters and commanders. It was not an easy shift, but it was necessary and exactly the reason I was put into the job in the first place.

In the end, I was pissed but knew that I had maintained my integrity and was determined in the few months I had left to continue the changes I was instituting and to keep beating the drum about the vicious enemy we were facing (still are).

I would not change a lick how I operate. Our country has too much at stake.

We’re in a global war, facing an enemy alliance that runs from Pyongyang, North Korea, to Havana, Cuba, and Caracas, Venezuela. Along the way, the alliance picks up radical Muslim countries and organizations such as Iran, al Qaeda, the Taliban and Islamic State.

That’s a formidable coalition, and nobody should be shocked to discover that we are losing the war.

If our leaders were interested in winning, they would have to design a strategy to destroy this global enemy. But they don’t see the global war. Instead, they timidly nibble around the edges of the battlefields from Africa to the Middle East, and act as if each fight, whether in Syria, Iraq, Nigeria, Libya or Afghanistan, can be peacefully resolved by diplomatic effort.

As we defeat them on the ground, we must clearly and forcefully attack their crazy doctrines. Defeat on battlefields does great damage to their claim to be acting as agents of divine will.

This approach is doomed. We have real enemies, dedicated to dominating and eventually destroying us, and they are not going to be talked out of their hatred. Iran, for example, declared war on the United States in 1979 — that’s 37 years ago — and has been killing Americans ever since. Every year, the State Department declares Iran to be the world’s primary supporter of terror. Do you think we’ll nicely and politely convince them to be good citizens and even (as President Obama desires) a responsible ally supporting peace? Do you think ISIS or the Taliban wants to embrace us?

No, we’re not going to talk our way out of this war, nor can we escape its horrors. Ask the people in San Bernardino or South Florida, or the relatives of the thousands killed on 9/11. We’re either going to win or lose. There is no other “solution.”

I believe we can and must win. This war must be waged both militarily and politically; we have to destroy the enemy armies and combat enemy doctrines. Both are doable. On military battlefields, we have defeated radical Islamic forces every time we have seriously gone after them, from Iraq to Afghanistan. Their current strength is not a reflection of their ability to overwhelm our armed forces, but rather the consequence of our mistaken and untimely withdrawal after demolishing them.

We have failed to challenge their jihadist doctrines, even though their true believers only number a small fraction of the Muslim world, and even though everybody, above all most living Muslims, knows that the Islamic world is an epic failure, desperately needing economic, cultural and educational reform of the sort that has led to the superiority of the West.

So first of all, we need to demolish the terror armies, above all in the Middle East and Libya. We have the wherewithal, but lack the will. That has to change. It’s hard to imagine it happening with our current leaders, but the next president will have to do it.

As we defeat them on the ground, we must clearly and forcefully attack their crazy doctrines. Defeat on battlefields does great damage to their claim to be acting as agents of divine will. After defeating al Qaeda in Iraq, we should have challenged the Islamic world and asked: “How did we win? Did Allah change sides?”

We need to denounce them as false prophets, as we insist on the superiority of our own political vision. This applies in equal measure to the radical secular elements of the enemy coalition. Is North Korea some sort of success story? Does anyone this side of a university seminar think the Cuban people prefer the Castros’ tyranny to real freedom? Is Vladimir Putin a model leader for the 21st-century world?

Just as the Muslim world has failed, so the secular tyrants have wrecked their own countries. They hate us in part because they know their own peoples would prefer to live as we do. They hope to destroy us before they have to face the consequences of their many failures.

Remember that Machiavelli insisted that tyranny is the most unstable form of government.

It infuriates me when our president bans criticism of our enemies, and I am certain that we cannot win this war unless we are free to call our enemies by their proper names: radical jihadis, failed tyrants, and so forth.

With good leadership, we should win. But we desperately need good leaders to reverse our enemies’ successes.

Flynn is the author of the new book “The Field of Fight” (St. Martin’s Press), out Tuesday.