BRUSSELS—NATO, a military alliance, is like a dollar bill: Its value rests on the faith people put in it.

Now that faith is under attack from Donald Trump and politicians allied to him.

Trump’s recent broadsides against European members of the North Atlantic Treaty Organization for not spending sufficiently on defense raised the question of whether shaming allies strengthens or weakens the alliance.

The attacks might prompt countries to boost military outlays , but NATO is more than just its troops and weapons. Its unity has proved a powerful force, too.

“Deterrence is in the mind of our adversaries,” said Secretary-General Jens Stoltenberg in response to Trump’s comments. “We should not undermine the credibility of NATO’s deterrence.”

NATO Secretary General Jens Stoltenberg gestures as he holds a press conference ahead of NATO Defence Ministers’ meeting at the Alliance’s headquarters in Brussels, Belgium February 14, 2024. He has warned against undermining the alliance’s perceived unity. REUTERS/Yves Herman

Created by a 12-country pact signed in Washington 75 years ago this April, NATO is enshrined in U.S. law by an act of Congress, Senate approval of the founding treaty. Today, more than 30 other countries have embedded NATO in their basic laws. All of them did it willingly, if not enthusiastically.

NATO calls itself the most successful military alliance in human history, and that isn’t hollow bragging or crass marketing. Never before have so many countries, representing almost one-eighth of the world’s population, pledged to protect each other so consistently, for so long. NATO prevailed in the Cold War, when the stakes were no less than nuclear annihilation.

NATO’s success stemmed from the certainty that, if needed, the U.S. would come to its allies’ aid. Article 5 of the Washington Treaty obliges all allies to defend each other against “an armed attack,” and each will assist by taking “action as it deems necessary.” For decades, the assumption was that Washington would send troops into harm’s way to defend its allies.

Trump, a former president and the presumptive Republican presidential nominee, is putting that article of faith into question .

Doubt spread by Trump’s questioning of NATO’s founding principle resonates externally and internally because it hasn’t just defended against foreign threats. NATO has also kept peace among centuries-old enemies.

Leffler-Warren-K.-photographer-LIBRARY-OF-CONGRESS https://hdl.loc.gov/loc.pnp/ppmsca.71146

United under NATO’s security umbrella, long-feuding neighbors including France and Germany have become close allies. Others, including Greece and Turkey, have kept animosities from turning to war. Were NATO to atrophy or disappear, it isn’t inconceivable European leaders would once again fear and rearm against each other.

Instead, Europe has experienced its longest period of peace and widespread prosperity ever, becoming a valuable market for U.S. companies. It is by far America’s biggest foreign investor.

While the U.S. has underwritten European security for years, the cost in money and lives was far less than intervening to end two world wars.

That return on investment is guaranteed by NATO through its pivotal roles deterring adversaries and reassuring allies, said former U.S. ambassador to NATO Ivo Daalder.

The alliance also gives the U.S. something that Russia, China and other major powers lack, said Stoltenberg, “And that is more than 30 friends and allies.”

Now Trump has threatened not to defend NATO members that don’t hit a spending target set a decade ago. Instead, he said, he would encourage Russia to “do whatever the hell they want” to underspending allies. He also questioned whether European countries would come to America’s aid in a crisis.

Europeans acknowledge they must spend more on defense, and most are doing it —driven primarily by concerns about adversaries to the east, not an ally to the west. And some Europeans are urging their partners to stop hyperventilating over every Trump campaign remark and instead focus on building their capabilities.

“All that whining and moaning about Trump,” said Dutch Prime Minister Mark Rutte , who is the leading candidate to succeed Stoltenberg as NATO secretary-general later this year, at the Munich Security Conference on Saturday. “I heard that constantly over the last couple of days. Let’s stop doing that.”

Still, Trump’s recent comments crossed a line, even if they were inflated with campaign-trail hyperbole. No former—and possibly future—commander in chief has ever openly stomped on NATO’s core tenet.

Trump’s pay-for-protection approach “is in essence a whole-life insurance policy for members,” said retired Army Lt. Gen. Douglas Lute, who served as NATO ambassador under former President Obama.

“It’s like he’s saying, ‘You pay your premiums or the policy lapses,’” Lute said. The campaign line resonates because voters understand life insurance, Lute said, but it weakens NATO’s certainty.

“Trump, when he denigrates Article 5 and NATO, achieves a greater effect in NATO members than Vladimir Putin ever could,” said Lute of Russia’s president. “It’s a strategic gift to Putin.“

President Biden called Trump’s comment un-American. European leaders and even some Republicans lashed out at Trump, accusing him of undermining U.S. security.

Vice President Kamala Harris , speaking at the Munich conference on Friday, noted that the sole time Article 5 has been invoked was by Europeans, in support of the U.S. after the terrorist attacks of Sept. 11, 2001.

NATO’s Stoltenberg said Trump’s remarks endangered troops from the U.S. and other allies by potentially emboldening Putin.

“Countries like China, Iran and North Korea are looking at how we are behaving,” said Dutch Defense Minister Kajsa Ollongren. “If they feel that maybe, after all, NATO wouldn’t act, then that can have consequences.”

When Trump was president, he grew so frustrated with low European military spending that he intimated he might pull the U.S. out of the alliance . His recent comment represents an attitude that could gut NATO without a single piece of legislation or executive order.

A president could refuse to invoke Article 5, or send only a token response, or obstruct allied responses, said Daalder, who served under Obama.

“You don’t have to withdraw to undermine NATO,” said Daalder. “You’re violating the spirit of the treaty, but not the law.”

Retired Army Gen. David Petraeus , a former Central Intelligence Agency director who led U.S. troop surges in Iraq and Afghanistan, said it is good news that European countries are increasing military spending, which should help bolster U.S. political support for NATO.

But post-Cold War conflicts in Libya, former-Yugoslavia and Afghanistan demonstrate that the U.S. will need to remain the indispensable backbone of NATO if the alliance is to endure, he said, in part for practical, technical reasons.

The U.S. is vital, he said, “because although the European countries can assemble on paper very substantial force and capability, then you get into the issues of interoperability and efficiency.” Without the U.S., deterrence “becomes exceedingly difficult.”

NATO has faced crises and hiccups before, but its fundamental premise never came into serious question.

During the Suez Crisis of 1956 and the second Gulf War in 2003, allies didn’t hide their anger with each other. In recent years, Trump hinted at an exit and French President Emmanuel Macron warned of “the brain death of NATO.” The alliance rebounded.

Putin’s large-scale invasion of Ukraine two years ago boosted NATO’s credibility . Ukrainian forces stopped Russian troops from taking Kyiv in part thanks to training they had received from NATO forces over the eight years following Moscow’s first push into their country.

After the 2022 invasion, NATO activated defensive procedures and rushed reinforcements to its easternmost members. It has since worked to orchestrate new battle plans, similar to ones jettisoned at the end of the Cold War, for alliance-wide operations involving hundreds of thousands of troops.

In a sign of NATO’s enduring appeal, Finland and Sweden shed decades of military neutrality and in 2022 applied to join the alliance. The high-spenders on defense will strengthen NATO. Finland’s accession took less than a year, while Sweden’s membership could become official within weeks.

To demonstrate deterrence capabilities, NATO is now staging its largest maneuvers since 1988, Steadfast Defender, involving roughly 90,000 troops from all 31 members and Sweden. The exercise will last months, stretching across the Atlantic and from the Arctic to near the Black Sea. The goal is to show that NATO can fight as one.

Among European leaders now, “there’s a great sense of urgency” to spend and achieve more to protect their countries, said Ollongren, the Dutch defense minister.

Write to Daniel Michaels at Dan.Michaels@wsj.com