President Obama announced the resignation of Defense Secretary Chuck Hagel at a joint news conference on Monday. Hagel will continue as defense secretary until the president nominates a successor, who must also be confirmed by the Senate. (Associated Press)

Defense Secretary Chuck Hagel bowed to pressure from the White House and submitted his resignation Monday after less than two years in the job, a casualty of the Obama administration’s infighting over national-security policy, especially regarding the Middle East.

Hagel said he will remain at the Pentagon until Obama can pick a replacement, who must then be confirmed by the Senate. Contenders include Michéle Flournoy and Ashton Carter, former high-ranking defense officials during Obama’s first term who were passed over for the top job in favor of Hagel.

Obama formally announced the change in a late-morning appearance at the White House. He said Hagel approached him last month and concluded that “it was an appropriate time for him to complete his service.” Neither Hagel nor the president gave a specific reason for the decision, and Obama gave no hint that he had asked Hagel to stay.

In brief remarks, Hagel said that serving as defense secretary “has been the greatest privilege of my life.” As the event concluded, Obama reached over to give him an awkward-looking hug.

Afterward, White House officials said Obama had lost confidence in Hagel’s ability to oversee the war against the Islamic State and U.S. military operations in Iraq and Syria.

Disagreements between the Pentagon and White House have been spilling into the open. In late October, administration officials leaked the fact that Hagel had written a tough memo to national security adviser Susan E. Rice, blasting the White House’s strategy for Syria. That squabble came one month after Obama appointed a retired general, John R. Allen, as his envoy in charge of assembling a coalition against the Islamic State — a job that some Pentagon officials saw as diminishing Hagel’s role.

White House press secretary Josh Earnest told reporters that Hagel’s Syria memo “did not have any effect” on his departure. He said that Hagel was picked for the job in large part to manage defense spending cuts and other bureaucratic changes but that with the rise of the Islamic State and other crises, Obama decided that “another secretary might be better suited to meet those challenges.”

Sen. John McCain (R-Ariz.), who is slated to take over as chairman of the Senate Armed Services Committee in January, acknowledged that he did not always agree with Hagel and voted against his nomination. But he said Hagel “was frustrated with aspects of the administration’s national security policy and decision-making process,” citing “excessive micromanagement” on the part of the White House.

McCain noted that Hagel’s predecessors as defense secretary — Robert M. Gates and Leon E. Panetta — had both likewise complained in their memoirs about excessive political interference from White House aides. “Ultimately, the president needs to realize that the real source of his current failures on national security more often lie with his administration’s misguided policies and the role played by his White House in devising and implementing them,” McCain said.

Rep. Howard P. “Buck” McKeon (R-Calif.), chairman of the House Armed Services Committee, said Hagel called him Monday morning to inform him of his pending resignation. “He said: ‘You know this town. You know the way it is,’ ” McKeon said.

He said that Hagel had “never said anything negative about the president to me” but that it was common knowledge he had butted heads with the White House.

When Obama nominated Hagel in January 2013, the president was intent on limiting defense spending, winding down the war in Afghanistan and keeping the military out of conflicts in the Middle East. He made clear that he was picking the decorated Vietnam War combat veteran in large part because Hagel understood “that sending young Americans to fight and bleed in the dirt and mud, that’s something we only do when it’s absolutely necessary.”

Since then, however, Obama has reluctantly been dragged back into the Middle East, signing deployment orders to send as many as 2,900 troops to Iraq to serve as advisers and trainers in the fight against the Islamic State. While the White House had hailed the conclusion of the war in Afghanistan, Obama in recent weeks quietly authorized expanded future combat operations in the country in light of a continuing insurgent threat there.

Hagel has been a quiet figure in most foreign-policy debates, particularly as the administration has struggled to articulate a strategy for defeating the Islamic State and stabilizing Iraq and Syria. In public, he largely ceded the stage to figures such as Secretary of State John F. Kerry and Army Gen. Martin Dempsey, the chairman of the Joint Chiefs of Staff.

In a sign of his identification with the military rank and file, Hagel was perhaps at his most forceful when he defended the decision to exchange Taliban detainees held at the Guantanamo Bay military prison for Bowe Bergdahl, an enlisted soldier who was held captive by the Taliban.

Rumors had intensified this month that Hagel’s time was short, though the Republican former senator from Nebraska had insisted in recent interviews that he was planning to stay at the Pentagon. The resignation was first reported by the New York Times.

“The bottom line is that Chuck Hagel took over at possibly the worst time anyone has seen in the last 20 years,” said Vikram Singh, a former deputy assistant secretary of defense who served under Hagel, citing the challenges of managing budget cuts, the repeated prospect of government shutdowns and several major conflicts overseas. “Given the state of affairs, I think he’s done a creditable job. . . . I think that he chose to be the quiet warrior and some people wanted a cheerleader.”

Hagel never quite recovered from a stumbling performance during his confirmation process. The Senate approved his nomination 58 to 41 in February 2013 — an exceptionally narrow margin, especially given the fact that he had served two terms in the Senate. Only four GOP senators voted for their fellow Republican.

Hagel served in the Senate with Obama, and the two bonded during overseas trips. Both were leading critics of the Iraq war during the George W. Bush administration. Hagel was known to have had a tense relationship with Rice, but defense officials said he tried to develop close ties with White House Chief of Staff Denis McDonough.

Unlike Panetta and Gates, Hagel in public was generally accepting of the White House’s push to keep a lid on defense spending, which had soared after the Sept. 11, 2001, attacks.

He was most visible in supporting Obama’s strategic “pivot” to Asia, taking numerous trips to visit allies in that part of the world. But his time spent in Asia came at the expense of making his presence felt in the Middle East and Afghanistan, which continued to dominate the national security agenda despite the White House’s desire to wind down U.S. military involvement in the region.

Defense officials described Hagel as much more focused more on policy — his reform initiatives and the Pentagon budget — than on military operations in places such as Iraq and Syria.