At first, the coup in Niger resembled others that have roiled West Africa in recent years. On July 26, soldiers detained Niger’s president at his home in the capital, Niamey. Hours later, they declared that they had seized power. Foreign powers condemned the putsch but did nothing.

Then the coup took a different course.

The United States and France threatened to cut ties with Niger, endangering hundreds of millions of dollars in aid. The deposed president, Mohamed Bazoum, though detained, was able to speak with world leaders, receive visitors and post defiant messages on social media.

Neighboring countries threatened to go to war — some to scuttle the coup, and others to ensure its success.

The Economic Community of West African States, a regional bloc of countries known as ECOWAS, issued an ultimatum to the junta on July 30: Restore Mr. Bazoum to power within one week or face the consequences, including possible military action.

Soon after, the neighboring countries of Mali and Burkina Faso leaped to the junta’s defense, declaring that they would consider any foreign move against Niger as a “declaration of war” against them, too. (Guinea also supported Niger’s military, but without the threat of force.)

What set off last week’s coup remains unclear. But in contrast with other recent takeovers in West Africa, which were largely greeted with shrugs, Niger’s coup has become a red line for many — including Western allies.

Thousands of American and French troops are stationed in Niger to help fight a surge in Islamist attacks across the region. That military cooperation is now suspended, as the United States and France exert pressure on the junta to restore democracy. European countries began evacuating their citizens on Tuesday; a day later, the United States ordered a partial evacuation of its embassy.

Britain advised “against all travel to the whole country.”

The turmoil and saber-rattling has exposed deep divisions in West Africa. The coup leaders insist they are going nowhere. With worries that the crisis could spill over into a regional war, the stakes are rapidly rising.

If the coup succeeds, Niger will be the last domino to fall in an unbroken line of countries stretching across Africa, from the Atlantic to the Red Sea, that are ruled by military juntas.

Democratically elected leaders are falling like bowling pins: Since 2020, three of Niger’s neighbors — Mali, Burkina Faso and Guinea — have experienced five coups.

Niger, though, seemed to be different.

Despite a long history of coups, the election of Mr. Bazoum as president in 2021 raised hopes that Niger was on a democratic path. An avowed modernizer, Mr. Bazoum promoted girls’ education, sought to reduce Niger’s birthrate, the highest in the world, and oversaw an impressive economic revival: After years of stagnation, Niger’s economy had been forecast to grow 7 percent this year.

Western countries saw Mr. Bazoum as a friendly figure in a rough neighborhood. Since mercenaries from Russia’s Wagner private military company, the spearhead of the Kremlin’s recent push into parts of Africa, were deployed to Mali last year, the United States and France have relied more heavily on Mr. Bazoum.

About 1,100 American troops and 1,500 French troops are based in Niger, as well as several drone bases. Foreign aid worth $2.2 billion makes up 40 percent of Niger’s national budget.

The alliance with the West helped Mr. Bazoum make Niger safer — fatalities from Islamist violence fell sharply last year. But it may also have stoked tensions inside the military, contributing to last week’s coup.

West Africa’s most powerful regional grouping, ECOWAS represents 15 countries with a combined population of about 400 million people. Although founded to bolster economies, ECOWAS has regularly waded into regional conflicts.

Since 1990, its peacekeepers have intervened to help quell rebellions, uphold cease-fires and force out dictators. The most recent mission was in Gambia in 2017, where its soldiers helped stop former President Yahya Jammeh from overturning an election he had lost.

Some want ECOWAS to emulate that example in Niger. The bloc’s head, President Bola Tinubu of Nigeria, says that West Africa cannot afford more coups and that ECOWAS needs to stop being a “toothless bulldog.”

“Tinubu is taking this Niger crisis personally,” said Rahmane Idrissa, a researcher at the African Studies Center of Leiden University in the Netherlands. “This was a one-coup-too-many for him, and for ECOWAS.”

On Wednesday, Nigeria’s military chief of staff, Christopher Musa, told Radio France International that if ordered, his forces were ready to deploy.

Still, many doubt that ECOWAS really wants to go to war over Niger. Gambia, where the bloc last deployed, is the smallest country on mainland Africa, with a weak army. Niger is twice the size of France, and its battle-tested army has been trained by American and European special forces.

“We will see if ECOWAS can ratchet up pressure any longer,” said Cameron Hudson, an Africa analyst at the Center for Strategic and International Studies. “But I suspect that their bluff has been called.”

Mr. Bazoum appears to be trapped in limbo.

Typically, during coups, ousted leaders are forced to flee or sign a formal resignation. Mr. Bazoum has done neither, instead staying at home to work the phones. On Wednesday, he spoke again with the U.S. secretary of state, Antony J. Blinken, and has also talked to President Emmanuel Macron of France.

President Mahamat Idriss Déby of Chad visited him on Sunday and later posted a photograph of the imprisoned president on social media.

Senior Nigerien diplomats still call Mr. Bazoum their boss.

“If this coup succeeds, it will be a disaster,” Kiari Liman-Tinguiri, Niger’s ambassador to the United States, said in an interview in which he called for international support to reverse the takeover. “A disaster for Niger, for the region and for the world.”

Gen. Abdourahmane Tchiani, the self-declared coup leader, has said he will not bow to the pressure.

As the head of Niger’s Presidential Guard for 12 years, General Tchiani has gone from being Mr. Bazoum’s protector to being his jailer.

Why he took that step is unclear. But in a television address on Wednesday night, General Tchiani sounded a defiant note, railing against “illegal, unjust and inhuman” sanctions imposed by ECOWAS on Niger since the coup.

And he reiterated that he would never reinstate Mr. Bazoum.

The sight of coup supporters brandishing Russian flags in central Niamey, some chanting slogans in favor of President Vladimir V. Putin, stoked suspicions that the Kremlin had a hand in the coup.

In fact, there is little evidence to support that idea, experts say. But that has not prevented Russian officials from seeing Niger’s crisis as a major opportunity.

Yevgeny V. Prigozhin, the Russian oligarch whose Wagner mercenary paramilitaries have been deployed to Mali, has pitched his services to Niger’s coup leaders. On Wednesday, one traveled to Mali’s capital, Bamako, where he met with Malian leaders and Wagner officials.

The other potential beneficiaries are the region’s Islamist militants. Since the coups in Mali and Burkina Faso, militants’ attacks on civilians in those countries have soared. But in Niger, they have dropped — a trend that many fear could now be reversed.

If the coup succeeds, “it could provide a large base, a sanctuary, to Wagner and the jihadists in the heart of West Africa,” Mr. Liman-Tinguiri, the diplomat, said. “This is not another coup as usual.”

Elian Peltier contributed reporting from Dakar, Senegal.