It is not the first time the president’s foreign policy has left Republican lawmakers crosswise with the White House, provoking their dissent in a way that perhaps no other issue has. In June, when Mr. Trump abruptly reversed his decision to launch a military strike against Iran after an American spy plane was shot down, national security hawks in his party, including Ms. Cheney, publicly lamented the decision. Mr. McConnell led Senate Republicans in January — as well as a group of Democrats — in delivering a pointed rebuke of the president’s announced withdrawal of United States military forces from Syria and Afghanistan.

Those who have frequently found themselves in lock step with Mr. Bolton, a cadre of hawkish lawmakers, many of whom have defense and military backgrounds, are now without a key ally in the White House. But they walked away early this week with a victory, praising Mr. Trump’s decision to cancel the negotiations to end the war with the Taliban. Those lawmakers have argued that Mr. Trump must not withdraw American forces from Afghanistan based on a political timetable, and that any deal with the Taliban should be viewed with the utmost skepticism.

“We can’t just wish the war away because it’s been long, hard and difficult,” said Representative Michael Waltz, Republican of Florida, who is a former Army Special Forces officer who served in Afghanistan. “Just because it’s difficult doesn’t mean it’s not worth doing. And in my view, we need to stay on offense, we need to keep our foot on their neck, we need them worrying about where they can sleep at night.”

The president’s frequent changes of heart on national security issues have also taught Republicans to hope that on crucial decisions, he will oscillate toward their preferred approach. He routinely voices frustration with the worldview that suggests the United States bears responsibility for patrolling the globe, and on Monday groused that soldiers in Afghanistan were serving, to a large extent, as policemen. Those comments have stoked hope among noninterventionists like Mr. Paul that the president will follow his instincts and make good on his campaign pledge.

“I’ve talked to him dozens of times, and I do believe the president wants to end the war in Afghanistan,” Mr. Paul said. “But he’s surrounded by people telling him all kinds of reasons why he can’t.”

Intent on ensuring Mr. Trump delivers on his campaign promise to end the forever wars, organizations like FreedomWorks, a libertarian advocacy group associated with the Tea Party, and Concerned Veterans for America, one of the arms of the Koch network, have mounted lobbying campaigns on Capitol Hill in an effort to provide political cover for Republicans who back ending military engagement in Afghanistan. They have found support from strident conservatives in the House, like Representative Matt Gaetz of Florida and Representative Andy Biggs of Arizona.

“At the end of the day, we didn’t end up in an endless war in Syria or Iran, and I think that is more reflective of the president’s view than his staff’s,” said Mr. Gaetz, a close ally of Mr. Trump’s. “I think the president has been pretty consistent in his desire to not start a new forever war, and I think the country can even be more heartened in that ideology with Mr. Bolton’s departure.”