WASHINGTON – Former defense secretary Jim Mattis, who resigned last year after clashing with President Donald Trump, says in a book excerpt that “I did as well as I could for as long as I could” and warns of the dangers of a leader who is not committed to working with allies.

Mattis, who announced his resignation in December after Trump shocked U.S. allies and overruled his advisers by announcing a troop withdrawal from Syria, writes in his book that he decided to depart “when my concrete solutions and strategic advice, especially keeping faith with our allies, no longer resonated.” The book is due to be published next week by Random House.

In the excerpt, published Wednesday by The Wall Street Journal, Mattis writes about the need for leaders to appreciate the value of allies without explicitly mentioning Trump, who has made a slogan of “America First.”

“Nations with allies thrive, and those without them wither,” Mattis writes. “Alone, America cannot protect our people and our economy. At this time, we can see storm clouds gathering. A polemicist’s role is not sufficient for a leader. A leader must display strategic acumen that incorporates respect for those nations that have stood with us when trouble loomed.”

Mattis argues for “returning to a strategic stance that includes the interests of as many nations as we can make common cause with.”

“Absent this,” he says, “we will occupy an increasingly lonely position, one that puts us at increasing risk in the world.”

The excerpt follows Trump’s attendance at last week’s Group of Seven summit in France, marked by his rejection of fellow global leaders’ climate change concerns, his call for Russian President Vladimir Putin to be readmitted to the G-7 despite the annexation of Crimea in Ukraine, and his erratic behavior toward trade negotiations with China.

Although Mattis’s views were no secret when he served in Trump’s Cabinet, he had maintained near-total public silence since resigning.

Trump’s Syria announcement, made on Twitter, was the immediate cause of Mattis’s departure. But the two officials were at odds over several issues almost from the time that the then-president-elect, following an introduction and 40-minute meeting with the retired Marine general, announced his nomination.

Calling him “Mad Dog Mattis,” a Marine nickname Mattis reportedly disliked, Trump referred to him as “one of our great, great generals.”

Over the next two years, Mattis played a major role in formulating Trump’s strategy against the Islamic State and in Afghanistan, and he successfully recommended that Trump lift more restrictive Obama-era rules of combat engagement. Viewed as an Iran policy hawk, he questioned the 2015 nuclear agreement with Iran but disagreed with Trump’s decision to withdraw from it. He voiced appreciation for military spending increases he had said were sorely needed.

But Mattis, who spent four decades in the Marines and held a number of senior commands, was seen as personally uncomfortable with the president’s scattershot policy pronouncements. While he largely kept his views of Trump to himself, he was outspoken on the threat posed by Russia and China and the need to preserve the international alliances that the president repeatedly denigrated.

Allied governments and foreign policy experts saw him as a stabilizing influence in a turbulent and unpredictable administration.

By last fall, however, his imminent departure was widely rumored. When a book by journalist Bob Woodward reported that Mattis had privately compared Trump to a “fifth- or sixth-grader,” Trump responded that Mattis was “sort of a Democrat” and noted that “he may leave” the Cabinet.

In his resignation letter to the president, Mattis said that “you have the right to have a Secretary of Defense whose views are better aligned with yours on these and other subjects.” While he offered a two-month transition to a new secretary, Trump announced his immediate departure.

Mattis retired to near seclusion at his home in Washington state, turning down almost all requests to publicly elaborate on his tenure in the administration. In March, he became a fellow at the Hoover Institution at Stanford University, reclaiming a position he had held before joining Trump’s team. He has also rejoined the board of the massive defense contractor General Dynamics.

In May, Random House announced that it would publish his book, co-written with Bing West, an author and former assistant defense secretary during the Reagan administration. Under a contract signed before he joined the Trump administration, the book was described as largely dealing with Mattis’s Marine career and leadership.

“I’m old-fashioned: I don’t write about sitting Presidents, so those looking for a tell-all will be disappointed,” Mattis said in a statement at the time. “I want to pass on the lessons and experiences that prepared me for challenges I could not anticipate, not take up the hot political rhetoric of our day.”

The title, “Chaos,” Random House said, referred to his Marine call sign in the 1990s.

But the excerpt published Wednesday deals extensively with the current domestic political climate. Mattis writes that he is more concerned today about “our internal divisiveness” than “our external adversaries.”

“We are dividing into hostile tribes cheering against each other, fueled by emotion and a mutual disdain that jeopardizes our future, instead of rediscovering our common ground and finding solutions,” he writes. “All Americans need to recognize that our democracy is an experiment – and one that can be reversed. We all know that we’re better than our current politics. Tribalism must not be allowed to destroy our experiment.”