WASHINGTON — There was no way President Donald Trump could sustain a fight for long with the American Legion over Old Glory and Sen. John McCain.

He's hung his hat — politically and on policy — on being a champion for veterans. So while Trump could ignore the pleas of many Americans to honor the former prisoner of war, onetime Republican presidential nominee and 35-year veteran of Congress by ordering U.S. flags to fly at half-staff, he couldn't turn a deaf ear to the nation's most prominent veterans organizations.

It wasn't just the American Legion, which called on him to reverse his decision to keep the flag at its full position about an hour before he reversed course. Joe Davis, national spokesman for the Veterans of Foreign Wars, told NBC News that the group made a similar request to the White House via email Monday morning.

"We have not received a response back yet, but hope they are in agreement," he said in a phone interview just before Trump relented. As it turned out — after many hours — the president had found his way to their side.

The pressure from the veterans groups had to make clear to Trump that it wasn't just a political loser for him to snub McCain but a threat to the brand he's tried to build by tying himself to America's passion for the military, its veterans and its flag.

Trump can't afford to have the nation's veterans turn their backs on him the way he turned his back — or held his flag at full-staff — to spite McCain. He needs to avoid angering them, both to protect his veterans agenda in Washington and for his re-election hopes.

McCain is not universally popular among veterans — and insulting McCain's service during the 2016 campaign didn't cost Trump the Republican nomination or the presidency — but turning the American Legion and Veterans of Foreign Wars into enemies would have been politically toxic.

Trump, who received educational and medical deferments from serving in the war that put McCain in a Vietnamese prison camp for five-and-a-half years, wants to throw himself a military parade in Washington in the midst of two wars that the U.S. has been engaged in for nearly two decades.

He's benefited politically from the support he's pledged to the military and the nation's veterans community — including his work on a spate of bipartisan laws designed to improve conditions at veterans medical facilities — as well as from the fact that many current and former servicemembers agree with him on a wide range of other issues.

His retreat in the face of pressure from veterans groups demonstrates that he understands there's a limit to how much he can insult a high-profile veteran without damaging his own standing. And while the pushback from the American Legion and VFW didn't rise to the level of harsh criticism — they simply asked him to honor McCain when he wasn't doing it — their willingness to take on a commander in chief obsessed with loyalty suggests that they have a certain influence with him that neither his critics nor most of his allies do.

And in a show of just how urgent it was for Trump to reverse course, the flags at the White House were lowered back to half-staff — where they had stood on Sunday before being returned to the tops of their poles Monday morning — before he issued the official order to federal agencies to honor McCain.

Trump doesn't like to back down from any fight. Yet he had no choice but to retreat when the leaders of millions of vets came knocking.