For almost seven years, Ecuador’s government weighed the risks and rewards of providing a haven to Julian Assange at the country’s embassy in London, a diplomatic high-wire act that put the small South American nation at odds with one of its most important partners.

By Thursday, Ecuadoran officials eager to improve trade and other relations with the United States and exasperated by what they described as the WikiLeaks founder’s overbearing presence had reached a decision.

A gambit that began as a show of anti-U. S. defiance by a leftist Ecuadoran president collapsed with Assange’s expulsion and arrest under that president’s more moderate successor.

“The patience of Ecuador has reached its limits,” President Lenín Moreno said after British police arrested a bearded Assange and escorted him to a vehicle.

Here is what you need to know about Julian Assange, the WikiLeaks founder who a British court sentenced to 50 weeks in prison May 1. (Sarah Parnass, Allie Caren/The Washington Post)

It had become increasingly clear in Ecuador that Moreno’s politics would lead eventually to Assange’s removal from the embassy. He now faces extradition to the United States to face a charge of conspiracy to hack a classified Defense Department computer.

The political scientist Joaquín Hernández said sympathy for Assange had dwindled in the nation of 17 million, where many had come to see him as a “political imposition.”

“The costs of maintaining him in the embassy and his ungrateful attitude were offensive,” said Hernández, dean of Universidad Espíritu Santo in Guayaquil.

The decision to grant refuge to Assange in 2012 was made by Moreno’s predecessor, Rafael Correa, a leftist whose relationship with the United States had grown increasingly contentious.

In 2007, Correa refused to renew the U.S. lease of a military base in Ecuador unless Ecuador could open its own base in Miami. He accused U.S. officials of spying on him. In 2011, he expelled the U.S. ambassador.

Sheltering Assange further strained the relationship.

U.S. authorities say Assange agreed to help a U.S. Army intelligence analyst break a password to the Defense Department’s computer network in 2010. In an indictment unsealed Thursday, prosecutors say Chelsea Manning, then known as Bradley Manning, gave WikiLeaks hundreds of thousands of classified U.S. records, including diplomatic cables and reports from the Afghanistan and Iraq wars.

Exports from Ecuador to the United States fell from $10.87 billion in 2014 to $7.47 billion in 2015, and Ecuador turned to China to finance massive infrastructure projects, with loans that swelled the national debt.

For a while, an oil boom helped buoy Ecuador’s economy. But the price of oil and other commodities fell, and by the time Moreno was elected president in 2017, he was forced to reckon not only with the geopolitical legacy of his predecessor but also with an economic recession.

Seeking help, Moreno signed a $4.2 billion loan agreement with the International Monetary Fund and inched closer to the United States.

Vice President Pence thanked Moreno in Quito last year for the improvement in relations.

“The actions that you’ve taken have brought us closer together once again,” Pence said.

Moreno called Assange a “stone in the shoe” and an “inherited problem.”

The relationship between Ecuador and Assange unraveled over issues large and small. Moreno accused WikiLeaks of intercepting his private messages and releasing private photos of his family. The embassy ordered Assange to pay for his own health care and to clean up after his cat.

“Mr. Assange has violated the agreement we reached with him and his legal counsel too many times,” Moreno said this month.

In the Ecuadoran parliament on Thursday, Foreign Minister José Valencia laid out a nine-point argument for why Assange had to leave the embassy, citing problems including bad behavior, deteriorating health and threats he allegedly made against Ecuador.

Assange “skateboarded, played soccer and physically shook a worker at the embassy,” Valencia said. “He used his speakers at 1:30 a.m.” He accused Assange of installing an unauthorized camera and bringing in suitcases and boxes that were not inspected.

Assange’s lawyers did not respond to Valencia’s claims. Lawyer Jennifer Robinson told reporters that “this precedent means that any journalist can be extradited for prosecution in the United States for publishing truthful information about the United States.”

Hernández, the political scientist, said it made no sense “to keep maintaining a man who fails to understand and despises the country.”

“Assange is grateful to Correa, not to Ecuador,” he said.

Francisco Rodríguez, chief economist at Torino Capital in New York, said the revocation of Assange’s asylum status seems to be “part of the political quid pro that comes with improving relations with the U.S.”

Moreno said that before expelling Assange, he received assurances from the British government that Assange would not be extradited to a country where he could be tortured or sentenced to death.

“The British government has confirmed it in writing, in accordance with its own rules,” Moreno said in a video posted on Twitter.

The charge on which Assange has been indicted does not carry the death penalty.

Alejandro Olivares, a political scientist with the Faculty of Latin American Social Sciences in Ecuador, said that expelling Assange is unlikely to be unpopular.

“In general, in Latin America and in Ecuador, there’s always a problem when a government does something which is seen as very pro-U. S.,” he said. “People ask, ‘Why are you doing the dirty work of the U.S.’ — especially in the Trump era.

“But in the specific case, it’s more of an issue between those who support Correa and those who don’t.”

Correa, now living in Belgium, is wanted by the justice system in his homeland over alleged links to a 2012 political kidnapping.

Moreno was once Correa’s vice president. But over the past year, he has been eager to distance himself from his former ally.

After Assange’s expulsion and arrest Thursday, Correa tweeted that Moreno was “the greatest traitor in Ecuadorian and Latin American history.”

Members of Ecuador’s parliament were divided over the decision Thursday.

“Why does the United States want him? To shut him up,” said one lawmaker, Juan Cárdenas. “In the United States there is the death penalty.”

He continued: “I ask the world to forgive an Ecuador that is not represented by this decision.”

But most supported the move.

“Every coherent Ecuadoran salutes this decision of the government,” said Marcelo Simbaña, a member of Ecuador’s parliament. “But it is strange how much time has passed. It was a series of historical errors that gave Assange asylum in 2012.”

Sieff and Martinez reported from Mexico City. Hernández reported from Caracas, Venezuela.