Former Defense Secretary James Mattis said he had "no choice" but to leave his job leading the nation's military following President Trump's controversial comments about some the United States' oldest and closest allies.

"I had no choice but to leave," Mattis told The Atlantic in a wide-ranging interview. "I want people to understand why I couldn't stay. I've been informed by four decades of experience, and I just couldn't connect the dots anymore."

He went on, "Let me put it this way. I've written an entire book built on the principles of respecting your troops, respecting each other, respecting your allies. Isn't it pretty obvious how I would feel about something like that?"

Get Breaking News Delivered to Your Inbox

Mattis quit as defense secretary after Mr. Trump ignored his advice and ordered U.S. troops out of Syria. In his resignation letter, Mattis referred to his strongly held "views on treating allies with respect," an apparent reference to Mr. Trump's complaints about the value of bedrock alliances like NATO.

"One core belief that I have always held is that our strength as a nation is inextricably linked to our unique and comprehensive system of alliances and partnerships," Mattis wrote. He also warned against closeness with countries such as Russia and China.

"My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors are strongly held and informed by over four decades of immersion in these issues," he added.

Angered by the blunt letter, the president moved to push Mattis out earlier than he had planned to leave.

Mattis, however, kept to his military-bred stoicism, refraining from launching an all-out attack on Mr. Trump in one of his first interviews since leaving the Pentagon.

"You don't endanger the country by attacking the elected commander in chief. I may not like a commander in chief one fricking bit, but our system puts the commander in chief there, and to further weaken him when we're up against real threats — I mean, we could be at war on the Korean Peninsula, every time they start launching something," Mattis said.

North Korea remains a concern for the former military chief. Mattis found the president's nonchalant approach to dictator Kim Jong Un and Mr. Trump's persistent downplaying of North Korea's nuclear capabilities particularly troubling.

"Any Marine general or any other senior servant of the people of the United States would find that, to use a mild euphemism, counterproductive and beneath the dignity of the presidency," Mattis said.

But Mattis contends that the current political environment is not because of Mr. Trump alone. Instead, he blames outside forces that elected him to office.

"We've got to address the things that put him there in the first place," Mattis said.