Not long after Defense Secretary Jim Mattis took over at the Pentagon, he set out to transform the U.S. military into a better-equipped, deadlier force that would waste less money, deepen alliances around the world, and evolve to counter Russia and China.

But President Trump soon began throwing curveballs his way.

The president has demanded a space force, a ban on transgender troops, a military parade, a National Guard deployment at the border and other politically tinged initiatives far from Mattis’s list of priorities.

Trump has launched impromptu broadsides against U.S. allies, threatened war with North Korea and pressed unconventional ideas regarding military operations, leaving Mattis scrambling to comfort U.S. partners or stop hasty decisions in their infancy. Though he hasn’t sought it out, the Pentagon chief has earned a reputation as the “reassurer-in-chief.”

The result is less time for the retired Marine Corps general to focus on the agenda he set for himself.

Mattis’s ability to execute his vision will largely determine whether he leaves a lasting mark on the armed forces or becomes known as the defense chief who spent the bulk of his tenure protecting the military and its alliances and stanching the impulses of an erratic president.

How far Mattis can go with his plans will also depend on how long he manages to stay in his job in an administration beset by upheaval and firings. U.N. Ambassador Nikki Haley’s resignation last week reignited speculation about whether Mattis would also exit soon.

In an interview with CBS News’s “60 Minutes” aired Sunday, Trump said he has a “very good relationship” with Mattis but that “it could be that he is” leaving, feeding speculation that the defense secretary could be out after the midterm elections.

“He may leave. I mean, at some point, everybody leaves,” said the president, who called Mattis “sort of a Democrat.”

In his 21 months running the department, Mattis, 68, has laid the groundwork for substantive changes but largely has yet to cement any hallmark, legacy-defining reforms to the way the armed forces train, fight and are equipped. One former official who worked for him said he gets an “A” for the first semester. The rest, the official said, is so far an “incomplete.”

“I think it’s clear that he has set out a vision. There’s generally no doubt about what that vision is, which is actually pretty meaningful in and of itself,” said Mara Karlin, a Pentagon strategist under President Barack Obama who now teaches at Johns Hopkins University.

“The next question is: To what extent is this vision being implemented?” she said. “Here I think the story is a little bit more mixed.”

This account of Mattis’s work was compiled after speaking to more than a dozen current and former officials in the Defense Department and elsewhere in the government. Some spoke on the condition of anonymity, citing the sensitivity of the discussions and their need to continue dealing with the Pentagon.

What emerges is a portrait of a secretary trying to reshape the military as he faces threats from enemies abroad, surprises from a mercurial president and concerns from allies about America’s future.

Questions about Mattis’s future arose most pointedly following the publication of a book by Bob Woodward that said Mattis compared Trump to a “fifth- or sixth-grader.” Mattis has described Woodward’s reporting as “fiction” and dismissed speculation that he would leave the Pentagon.

The Pentagon declined to address questions about Mattis’s future directly on Sunday. “Secretary Mattis is laser-focused on doing his job — ensuring the U.S. military remains the most lethal force on the planet,” Col. Rob Manning, a spokesman for the Defense Department, said in a statement.

The rumors have drawn attention away from what Mattis would prefer to discuss: his vision for the U.S. military.

Mattis articulated his concept early this year in a new national defense strategy that defined great-power competition with Russia and China as the military’s top priority — and minimized the focus on counterterrorism and threats from rogue nations.

He played a critical role in securing a two-year budget deal from Congress that lifted caps on military spending and plunged $716 billion into defense in the coming fiscal year, a salve for a force worn down by uncertain funding and 17 years of war.

All the while, he has largely insulated the Pentagon from the type of politicization that Trump has inflicted on the CIA and the FBI.

Mattis has convinced allies that they can still count on the U.S. military to defend them, despite Trump’s whipsaw comments, while persuading them to contribute more to their own defense.

But Mattis so far has enacted few large-scale changes certain to outlast his tenure. He hasn’t initiated the cancellation or introduction of any marquee weapons programs or systems. His plan to build a more lethal force remains in the early stages. With a few exceptions, his effort to drive efficiency across the Pentagon has stalled, by many accounts.

Most critically, the difficult, in-the-trenches work of rewiring a giant bureaucracy to focus on countering Moscow and Beijing is largely still on paper. Key policy documents on that front, such as a long-delayed missile defense review, haven’t been released. Some analysts argue that to devote sufficient resources to that goal, Mattis would ultimately need to draw down in Afghanistan; so far he has done the opposite, with no end to the expenditures in sight. The war is among Trump’s greatest frustrations with Mattis, officials say.

“He now needs to apply his vision and strategy across the joint force deliberately and with the same ruthlessness he has always applied to his past operational campaigns,” said Frank Hoffman, a defense analyst who served under Mattis in the Marines and at the Pentagon.

Chief Pentagon spokeswoman Dana W. White said that change takes time and that the entire department is in the process of implementing Mattis’s defense strategy. She credited Mattis with securing the “largest increase in defense spending in decades in record time with overwhelming bipartisan support in a very politically divisive environment.”

Bureaucratic challenges

Mattis’s more than 40 years in uniform prepared him to prosecute military campaigns and craft high-level strategy for national security threats, but he spent relatively little time at the Pentagon. He is coupled with Deputy Defense Secretary Patrick Shanahan, a former executive at Boeing, leaving the top two offices in the building without a leader schooled in slashing through Washington’s bureaucratic thicket.

Analysts say that for the Pentagon to better counter Russia and China, it must use fewer vulnerable ships and fixed bases that can be easily attacked and fly fewer short-range aircraft. The military also must fully embrace cyber and electronic warfare, artificial intelligence, hypersonic missiles, and defenses in space — areas that have received limited attention in recent years.

Elbridge Colby, a former Pentagon official under Mattis, praised the secretary for pushing through a new and refocused vision but emphasized the enormousness of the task at hand.

“Implementing it will require significant, and in many respects dramatic, changes to the defense budget, how the armed forces fight and almost everything else the department does,” Colby said.

Shanahan said recently that Mattis’s skills extend well beyond being a leader and motivator and that he has learned a lot from him.

“He understands how to govern,” Shanahan said at the annual Air Force Association conference. “He understands how government should work. He understands policy. He understands the law. He understands the value of relationships.”

Whether the defense secretary has the skills and opportunity to reinvent the U.S. military is another question.

One former official said Mattis’s mind is either “a guy in the mud, a commander in the field, or he’s operating on a George Shultz level,” a reference to the former secretary of state and well-known foreign affairs strategist. It is difficult for Shanahan to fill the gap because, according to a different former official, “he’s not learning the culture of the building” and has struggled with high turnover on his immediate staff and tensions with the military services.

White, the chief Pentagon spokeswoman, said Mattis chose Shanahan for a reason. “He brings new thinking to complex challenges,” she said. “He infuses common sense and holds people accountable to think and act differently.”

Tension with Trump

Top Pentagon officials promise that their budget request for the next fiscal year — slated for public release in early 2019 — will offer proof that the department is seeing through hard choices to reorient and restructure the military. Shanahan has called the budget document “the masterpiece.”

That masterpiece could run into significant challenges if Democrats take control of the House or the Senate in the November midterm elections or if a follow-on budget deal fails to materialize on Capitol Hill. A departure by Mattis could also set back the effort to reshape the military.

At least half a dozen current and former officials familiar with the situation noted that reports of Trump’s occasional displeasure with Mattis began surfacing this spring, when national security adviser John Bolton named as his deputy Mira Ricardel, an undersecretary of commerce who, the officials said, clashed with Mattis while leading Trump’s transition. Her reemergence at the White House has fueled suspicion at the Pentagon that she is undermining Mattis, they said.

Ricardel, in a statement released by the National Security Council, said, “The NSC is coordinating across government agencies to implement the President’s agenda, including with the Defense Department under the leadership of General Mattis, for whom I have great respect.”

Officials familiar with Mattis’s thinking said he has made no plans to leave the job, considers it his duty to stay and isn’t by nature a quitter. “He is not going anywhere,” White said.

If Trump wants Mattis out, officials said, the president will probably have to fire him.

Such a dismissal could provoke a backlash in Trump’s political base, considering Mattis’s distinguished military career and popularity with many conservatives and rank-and-file troops.

“The troops memorialize his quotes as gospel,” said Jeff Davis, a retired Navy captain who served as director of press operations at the Pentagon. “He is revered and respected orders of magnitude more than any secretaries we have had.”

Still, few officials would rule out the possibility that the president might dismiss Mattis at some point after the midterm elections, particularly amid possible looming policy disagreements with the White House over how the administration should approach Iran and Syria.

At times, Mattis has been out of step with many of the president’s foreign policy impulses. Trump remains deeply suspicious of U.S. involvement in Afghanistan, even after signing off on a strategy Mattis backed 13 months ago that modestly increased the number of U.S. troops there to nearly 15,000 while stepping up airstrikes against the Taliban.

U.S. officials have sought to show that the war in Afghanistan is going smoothly, with few U.S. fatalities and no major cities falling into Taliban hands permanently. It remains to be seen whether Trump will show patience with a stalemated conflict in which Mattis’s plan is to pressure the Taliban to negotiate a peace deal despite a lack of clarity over whether the militant group is willing to do so.

Mattis has received plaudits from the president for his handling of the campaign against the Islamic State, largely a continuation of the Obama administration’s effort. The defense secretary has also helped temper Trump’s onetime desire to remove U.S. troops from Syria immediately. A hasty U.S. departure from the country would risk a resurgence of the extremist group in Syria, Mattis has argued. Now the administration is arguing that U.S. troops should stay until Iran leaves.

Mattis advocated against putting military exercises on the table in talks with North Korea, implementing national security tariffs, slashing refu­gee acceptance numbers and pulling out of the Iran nuclear accord, former officials said. He lost each time.

Christopher Preble, vice president for defense and foreign policy studies at the libertarian Cato Institute, said Trump came into office promising to reduce military interventions abroad and guarantees to wealthy allies, but largely hasn’t done so — and Mattis is the symbol of that.

“He is a source of continuity in an administration that was elected in part on the basis of change,” Preble said.

Less waste, more 'lethality'

At the Pentagon, Mattis has also set a goal of instilling budget discipline and cutting waste.

In internal discussions, the Pentagon aimed to save $100 billion over five years in cuts to overhead and other programs. But officials soon decided that was too ambitious and scaled back the target to $46 billion over five years, according to a former senior Pentagon official.

One of the top officials in charge of engineering the savings, Chief Management Officer John “Jay” Gibson, is on his way out, according to a recent report in the Wall Street Journal. The Pentagon declined to comment on Gibson’s future.

The top civilian official in the Army recently announced that the service had freed up about $25 billion in expenditures that can be applied to other priorities. He said the changes would be evident in the service’s coming budget request.

Meanwhile, Mattis has been touting the first agencywide audit of the Pentagon’s books. Pentagon officials defended the audit’s nearly billion-dollar price tag as small, compared with the size and complexity of the Defense Department’s budget.

Budget hawks question whether Mattis can substantively reduce Pentagon waste at a time when so much new money is being pumped into the system.

Above all, Mattis has emphasized “lethality,” which has become a new Pentagon watchword for the secretary’s effort to make the force deadlier.

This year, he formed the Close Combat Lethality Task Force, which is examining how to improve weapons, training and resiliency for infantrymen and others who fight alongside them.

The task force has made few announcements, but retired Army Maj. Gen. Robert Scales, an adviser for the group, said it is weighing ideas that Mattis has considered for at least a decade, such as fielding new rifles that shoot larger ammunition.

The effort has had other consequences, with lower-down officials at the Pentagon applying the term “lethality” to existing initiatives as an effort to satisfy the boss. Todd Harrison, director of defense budget analysis at the Center for Strategic and International Studies, said the word risked losing significance.

“You can’t just apply the word ‘lethal’ to everything the military does,” he said. “It just does not make sense.”