President Obama and one of his most trusted military advisers, Marine Gen. James E. Cartwright, at the White House on May 4. (Evan Vucci/AP)

President Obama summoned one of his favorite and most trusted military advisers, Marine Gen. James E. Cartwright, to the White House on May 21 for a one-on-one meeting. It was a Saturday, less than three weeks since the president had celebrated the death of Osama bin Laden with Cartwright and other members of his national security team. But this time, the president had bad news.

Over the previous year, Obama had asked Cartwright on three occasions if he’d be willing to serve as the chairman of the Joint Chiefs of Staff, the highest-ranking officer in the armed forces and principal military adviser to the president. According to two military officials close to Cartwright, who has served as vice chairman of the Joint Chiefs since 2007, the general demurred the first two times, saying he was looking forward to retirement after a 40-year military career.

But in recent months Cartwright, 61, had relented and told the president he’d be willing to take the job when the term of the current chairman, Adm. Mike Mullen, ends, according to the military officials. That conversation didn’t include a formal job offer from Obama, but he reportedly told Cartwright, “You’re my guy.” Others in the White House and Pentagon also saw him as the leading contender.

Cartwright, however, did not end up as Obama’s guy. In recent weeks, the cerebral but introverted general, who goes by the nickname “Hoss,” became the casualty of a concerted lobbying campaign by critics inside the Pentagon who persuaded the president to bypass him.

Obama has since settled on Army Gen. Martin E. Dempsey as his pick to become chairman, effective Oct. 1, said two U.S. officials speaking on the condition of anonymity because the decision has not been made public. The White House said Obama will make “personnel announcements” Monday regarding the Defense Department.

When Obama met with Cartwright on May 21, he told the general that Mullen and Defense Secretary Robert M. Gates — both of whom had long mistrusted Cartwright because of his independent relationship with the president and for opposing their plan to expand the war in Afghanistan — had recommended that he not get the job, said the military officials close to the general.

Someone to trust

Since taking office as a wartime president in 2009, Obama has struggled at times to surround himself with military commanders whom he trusts and feels personally comfortable with. Last summer, Obama sacked Gen. Stanley A. McChrystal, commander of U.S. forces in Afghanistan, after a magazine article quoted his staff mocking civilian leaders in the Obama administration.

McChrystal’s replacement, Gen. David H. Petraeus, a hero of the Iraq war, was seen by many Pentagon officials as a natural choice to lead the Joint Chiefs eventually. Obama seemed to get off to a cool start with Petraeus, with some White House officials eyeing him as a potential political rival and noting his close ties to former president George W. Bush. Last month Obama nominated Petraeus to take over the CIA, a plum job but one that will end his military career.

Since then, Obama’s rejection of Cartwright has ignited a chain reaction of unplanned personnel moves at the Pentagon as the White House scrambled to find someone else to head the Joint Chiefs.

The decision to tap Dempsey will cause further leadership disruptions. Obama had appointed Dempsey as the new Army chief of staff just last month, and now he’ll have to find a quick replacement.

The president might also need a new commander for the Air Force. Pentagon insiders said Gen. Norton A. Schwartz, the Air Force chief of staff, is a candidate to become vice chairman of the Joint Chiefs when Cartwright retires in August.

Obama also will need to name a new chief of the Navy to replace retiring Adm. Gary Roughead.

Overall, White House officials say Obama has built a strong relationship with military brass at the Pentagon, citing his decision to expand the war in Afghanistan while drawing down forces in Iraq, as well as the bin Laden takedown.

Tommy Vietor, a spokesman for the National Security Council, said the president has “enormous trust” in Petraeus and still holds McChrystal in “very high esteem,” calling the reason for his firing a “discrete incident.” Obama has since asked McChrystal to serve on an advisory board to support military families.

The White House declined to comment on Obama’s decision not to nominate Cartwright but offered high praise for the general.

“Each of the chiefs has a statutory obligation to give the president his best military advice,” Vietor said. “General Cartwright always does so, and it is one of the many reasons the president values General Cartwright so much.”

Cartwright declined to comment for this article. Supporters of the general, however, said he ultimately paid a political price for giving independent military advice to Obama that sometimes conflicted with counsel provided by Gates — his civilian boss at the Pentagon — and Mullen.

During the White House’s strategy review of the Afghan war in 2009, Mullen, Gates and Petraeus all backed an option to deploy 40,000 more troops. Obama was leery and pressed Cartwright on whether he thought it was the right approach. In response, Cartwright presented an alternative plan to send half as many extra troops.

“He was very aware he was providing guidance that was not in alignment” with the rest of the Pentagon, said a military officer close to Cartwright who spoke on the condition of anonymity to discuss internal deliberations with the White House. But Cartwright felt compelled to give an independent assessment to the president, even if it risked alienating Gates and Mullen, the military officer said. “He was told [by Obama], ‘No, don’t just give me the old line, Hoss. Give me your opinion.’ ”

Officials close to Gates and Mullen acknowledged that the episode strained their relationships with Cartwright. But they said the general’s mistake was not in giving unvarnished advice to the White House, but rather failing to keep them in the loop about what he was telling Obama.

A battle on the Hill

Richard H. Kohn, an expert on military-civilian relations and a professor emeritus of history at the University of North Carolina at Chapel Hill, said the Afghan review heightened Obama’s wariness of military commanders because he suspected that those pushing for the larger expansion of the war were trying to box him in to approving their plan.

“My sense is that Cartwright behaved properly in trying to figure out some alternatives for the administration to revise its Afghan strategy,” Kohn said. “It was a problem of both Gates and Mullen not understanding the proper role of the military. They’re not supposed to be providing one option and that’s all you get.”

Over the past year, as it became apparent that the president was strongly considering Cartwright to become chairman of the Joint Chiefs, his opponents lobbied against him behind the scenes. Critics emphasized his lack of combat experience and what they called an insular leadership style.

In February, sources at the Pentagon leaked the results of an unflattering inspector general investigation into allegations that Cartwright had a sexual relationship with a subordinate female officer. Investigators found no evidence of such a relationship, but they did criticize the general for not disciplining the woman, who had passed out on a bench in his hotel room after drinking too much on a business trip.

Cartwright and his wife separated shortly after the report’s release, giving more fuel to detractors.

His critics predicted that Cartwright would have difficulty winning confirmation in the Senate. They said he lacked support among Republicans, particularly Sen. John McCain (Ariz.), the ranking member on the Armed Services Committee, and female lawmakers.

Brooke Buchanan, a spokeswoman for McCain, said the senator had not signaled that he would oppose Cartwright’s nomination. “Senator McCain has never publicly, or privately for that matter, said he would give Gen. Cartwright resistance,” she said in an e-mail.

Sen. Dianne Feinstein ­(D-Calif.), chairman of the Intelligence Committee, also reacted sharply this month when news organizations reported that speculation about Cartwright’s personal life were torpedoing his chances to lead the Joint Chiefs.

“I have been advised that some are attempting to impugn General James Cartwright’s reputation,” Feinstein said in a statement. “I deeply regret this since he is one of America’s most respected four-star generals.”

Spokesmen for Gates and Mullen declined to comment on why they did not endorse Cartwright for the chairman’s job. But Geoff Morrell, the Pentagon press secretary, said Gates was “disgusted by the apparent rumor-mongering. He has the highest regard for General Cartwright, his extraordinary service to the nation and the job he has done as vice chairman.”

Staff writers Greg Jaffe and Scott Wilson and staff researcher Julie Tate contributed to this report.