CARACAS, Venezuela — Not far from Venezuela’s presidential palace, a group of civilians and soldiers clutched rifles in a recent military drill. Their mission: block the street leading to the residence of President Nicolás Maduro in the event of an American invasion.

After months of street unrest and growing international isolation, Maduro has found a new raison d’etre in President Trump’s threat last month to use military force in Venezuela. The exercises here were just one of a multitude of operations being orchestrated by the socialist government as it rallies a nation to arms.

The effort here underscores the power of Trump’s words, even off-the-cuff comments that may hint more at his mercurial nature than actual U.S. policy. International affairs experts do not take Trump’s threat of military force seriously. Yet Maduro loyalists are leveraging it to try to unite a divided country.

In recent weeks, pro-government broadcasts and social media posts have featured images of elderly women learning to shoot rifles and middle-aged men running military obstacle courses. Fishermen have gathered in boats to practice repulsing a sea offensive by “Los Yanquis.” Nearly two weeks ago, the government encouraged citizens ages 18 to 60 to sign up for pro-government militias.

Observers call it nationalistic theater, perhaps a way for Maduro to deflect public attention from food shortages and growing authoritarianism in a country with the world’s highest inflation rate. Nevertheless, analysts say the campaign shows the extent to which Trump’s threat has succeeded in giving the government a powerful new talking point.

“The statements [by Trump] regarding a military option clearly backfired,” said David Smilde, a Venezuela specialist at the Washington Office on Latin America.

Since the era of former president Hugo Chávez, the leftist firebrand who came to power in 1999, the Venezuelan government has cultivated a rivalry with the United States. Before he died in 2013, Chávez hinted that Washington could somehow have caused a wave of cancer cases affecting several Latin American leaders — including him.

Yet Trump’s threat has been manna from heaven for the unpopular Maduro, Chávez’s designated successor. In comments to reporters Aug. 12, Trump said: “We have many options for Venezuela, including a possible military option if necessary.”

Almost immediately, Latin American nations that have condemned Maduro were put in the uncomfortable position of having to effectively take his side against the threat of U.S. force. Maduro was also quick to use Trump’s comments to paint his domestic opponents — many of whom have called for more U.S. pressure on Caracas — as treasonous.

His government has sought to keep Trump’s words in the national consciousness weeks after they were lost in the blizzard of the Washington news cycle. The government is also seeking to link the threat to a tough round of U.S. sanctions announced two weeks ago that make it harder for Venezuela to access foreign debt markets. Authorities are feeding a narrative that the country’s skyrocketing inflation, rising poverty, and food and medicine shortages are the product of “imperialist” Washington.

On the one hand, Maduro has sought to defuse rising tensions with the United States — placing a call to Trump last month that the U.S. leader refused to take. Later in August, Maduro said he would send a personal letter to Trump in the hopes of reducing “tensions.”

Yet on Aug. 25, when the new U.S. sanctions were announced, Maduro held a televised meeting with government officials and leaders of the oil sector. He accused the United States of having an “extremist government that looks at us, the brown-skinned people from the south, as less than them.” He accused Trump of trying to “suffocate Venezuela’s productive economy” through a “brutal economic war.”

His surrogates, meanwhile, have encouraged the idea that this nation is facing a real and present danger. Last week, not far from the joint civilian-military drills near the presidential palace, senior Maduro backers led a pro-government rally. The president of Maduro’s newly elected all-powerful assembly, Delcy Rodríguez, opened the event with a charged speech echoing a message that the government has been reinforcing with tweets, cartoons and official statements: that Venezuela is under threat from the United States.

The Americans “took off their mask,” she said. “It’s time to defend ourselves.”

She has announced that pro-government lawmakers will launch a national tour “so that our people are able to have maximum knowledge to accompany our president against imperial aggression.”

In recent days, government officials have shared photos of nationwide drills on social media.

Teenagers in civilian clothes are shown marching alongside uniformed soldiers and the ­Bolivarian Militia — a group of ­military-trained civilians created by Chávez in 2008. In one image, an older civilian is trained how to use a bazooka.

On national TV, videos of civilians in military training are constantly appearing, along with messages from top officials voicing pride in the ordinary people “defending the homeland.” Venezuelan officials claimed that 220,000 soldiers, 537,000 militiamen and 343,000 ordinary citizens participated in drills across the country last week alone.

“We do this to demonstrate to Trump that gringos don’t belong here,” a woman wearing a pro-government shirt said in one video tweeted by Maduro last week.

Óscar Rojas, a systems engineer and civilian member of Venezuela’s Bolivarian Militia, participated in some of the exercises in Caracas.

“In a way the pressure from abroad is positive,” said Rojas, wearing a Fidel Castro-like beret and a shirt bearing Chávez’s eyes, a popular symbol of the ex-leader. “It awakens our nationalist sentiment.”

In an interview, Communications Minister Ernesto Villegas called the drills a way “to familiarize citizens with the need to defend the nation” and “dissuade any country from thinking it can intervene with no costs.”

He added, “I wouldn’t say the threats benefit the government because it would make it seem like we celebrate them, and we definitely don’t.”

“But certainly,” he continued, “if Trump thought his threats would terrify or intimidate the Venezuelan people, he made a very bad calculation. . . . I do not disconnect Trump’s military threat from what he ended up signing — the executive order that openly declares an economic war on Venezuela.”

Trump’s threat has put the opposition in a tight spot. Claiming that Maduro’s critics have lobbied for U.S. sanctions, a pro-government truth commission is investigating senior opposition leaders on suspicion of treason. The opposition representatives have also been accused of actively seeking U.S. military intervention — an allegation they deny.

Félix Seijas Rodríguez, a political analyst and director of the Delphos polling agency, said that he does not expect the government’s efforts to spark a rebound in its waning approval rating, which hovers around 20 percent, according to polls. Nevertheless, the campaign could serve to consolidate support among government backers and deflect some of the internal pressure on Maduro.

“Anything that happens from now on will be blamed on the U.S.,” said Moisés Naím, an author and former Venezuelan trade minister who is now a fellow at the Carnegie Endowment for International Peace in Washington. “Trump and [Vice President] Pence basically threw Maduro a lifeline.”