Without quoting what the president said, Mr. Caro said it was clear Mr. Obama understood that precedent. “Any president with a grasp of history  and it seems to me President Obama has a deep understanding of history  would have to be very aware of what happened in another war to derail a great domestic agenda,” he said.

Afghanistan, of course, is not exactly Vietnam. At its peak, the United States had about 500,000 troops in Vietnam, compared with about 68,000 now set for Afghanistan, and most of those fighting in the 1960s were draftees as opposed to volunteer soldiers. Vietnam, therefore, reached deeper into American society, touching more homes and involving more unwilling participants. But the politics of the two seem to evoke comparisons.

Just as Mr. Johnson believed he had no choice but to fight in Vietnam to contain communism, Mr. Obama last week portrayed Afghanistan as the bulwark against international terrorism. “This is not a war of choice,” he told the Veterans of Foreign Wars at their convention in Phoenix. “This is a war of necessity. Those who attacked America on 9/11 are plotting to do so again. If left unchecked, the Taliban insurgency will mean an even larger safe haven from which Al Qaeda would plot to kill more Americans.”

Image Helicopters in South Vietnam in 1971. Credit... U.S. Army

But while many Americans once shared that view, polls suggest that conviction is fading nearly eight years into the war. The share of Americans who said the war in Afghanistan was worth fighting slipped below 50 percent in a survey released last week by The Washington Post and ABC News. A July poll by the New York Times and CBS News showed that 57 percent of Americans think things are going badly for the United States in Afghanistan, compared with 33 percent who think they are going well.

That growing disenchantment in the countryside is increasingly mirrored in Washington, where liberals in Congress are speaking out more vocally against the Afghan war and newspapers are filled with more columns questioning America’s involvement. The cover of the latest Economist is headlined “Afghanistan: The Growing Threat of Failure.”

Richard N. Haass, a former Bush administration official turned critic, wrote in The New York Times last week that what he once considered a war of necessity has become a war of choice. While he still supports it, he argued that there are now alternatives to a large-scale troop presence, like drone attacks on suspected terrorists, more development aid and expanded training of Afghan police and soldiers.