Supporters of Venezuelan opposition leader Juan Guaido exited the country's embassy in Brazil on Wednesday, an official said, ending a standoff with rival backers of President Nicolas Maduro.

Guaido's appointed ambassador Teresa Belandria confirmed in a statement the supporters had left, hours after the struggle for control of the diplomatic compound began.

"We have instructed our staff to withdraw from the embassy in Brasilia because we cannot guarantee their safety owing to violence generated by the usurpers of the Nicolas Maduro regime," Belandria said.

Militarized police outside the Venezuelan embassy in Brasilia, Brazil as supporters of President Nicolas Maduro and opposition leader Juan Guaido vie for control of the diplomatic compound
Militarized police outside the Venezuelan embassy in Brasilia, Brazil as supporters of President Nicolas Maduro and opposition leader Juan Guaido vie for control of the diplomatic compound AFP / VALERIA PACHECO

Military police had surrounded the embassy in Brasilia as President Jair Bolsonaro met China's President Xi Jinping at the nearby foreign ministry, ahead of a BRICS summit of major emerging economies.

Belandria said her team was in talks with Brazilian authorities in order to "access our headquarters in the shortest possible time."

She said earlier that staff members at the embassy "voluntarily" opened its doors Wednesday to officials working for her.

China's President Xi Jinping (L) and Brazil's President Jair Bolsonaro (R) wave before a bilateral meeting in Brasilia ahead of a summit of the BRICS countries
China's President Xi Jinping (L) and Brazil's President Jair Bolsonaro (R) wave before a bilateral meeting in Brasilia ahead of a summit of the BRICS countries AFP / Sergio LIMA

More than a dozen Guaido supporters had partially occupied the embassy, said a Maduro backer inside the diplomatic compound where 15 people live.

Hundreds of people had gathered outside, many of them supporters of Brazil's left-wing Workers Party (PT), yelling "Viva Maduro," "Drug dealer Guaido" and "Free Lula," the Brazilian leftist icon released from jail on Friday.

Police detained two people after scuffles broke out between Guaido and Maduro supporters.

Russian President Vladimir Putin (R) and Indian Prime Minister Narendra Modi shake hands during their meeting on the sidelines of the BRICS summit, in Brasilia, Brazil, on November 13, 2019.
Russian President Vladimir Putin (R) and Indian Prime Minister Narendra Modi shake hands during their meeting on the sidelines of the BRICS summit, in Brasilia, Brazil, on November 13, 2019. POOL / Pavel Golovkin

The last Maduro-appointed ambassador to Brazil was withdrawn in 2016.

In her first statement, Belandria asked that all accredited officials at the embassy and Venezuela's seven consulates in Brazil recognize Guaido as the legitimate president.

More than 50 countries, including Brazil, recognized the Venezuelan opposition leader as acting president earlier this year after rejecting Maduro's re-election as fraudulent.

BRICS titans China and Russia, however, back Maduro.

China's President Xi Jinping (L) and Brazil's President Jair Bolsonaro wave before a bilateral meeting in Brasilia ahead of a summit of the BRICS countries
China's President Xi Jinping (L) and Brazil's President Jair Bolsonaro wave before a bilateral meeting in Brasilia ahead of a summit of the BRICS countries AFP / Sergio LIMA

"Upon entering the headquarters, we could verify that a group of officials was living in the official residence," said Belandria, who is not inside the embassy.

Freddy Menegotti, a senior embassy official loyal to Maduro, said earlier that "strangers to our facilities are entering and are violating the Venezuelan territory," according to a voice recording sent to the PT and shared with AFP.

"We need help, we need the immediate activation of all social movements and political parties," Menegotti said.

Factfile on the BRICS group of countries
Factfile on the BRICS group of countries AFP / John SAEKI

Venezuelan Foreign Minister Jorge Arreaza condemned what he described as an invasion of the embassy.

"We hold the Government of Brazil responsible for the safety of our staff and facilities," Arreaza tweeted.

"It is a delicate situation," said Paulo Pimenta, a member of PT, in a voice recording sent to AFP via WhatsApp.

Pimenta said he was among 10 Brazilians to enter the embassy in the morning.

Hours after the confrontation began, Bolsonaro tweeted: "We reject the interference of external actors. We are taking the necessary steps to safeguard public order and prevent acts of violence."

Venezuela's economy has been devastated by a political and economic crisis that has forced millions to flee, many of them into neighboring Brazil.

The BRICS summit will be the first time Bolsonaro, notoriously awkward at public events, has hosted a major international gathering since he took office in January.

Along with Xi, Russian President Vladimir Putin, Indian Prime Minister Narendra Modi and South African President Cyril Ramaphosa will attend the annual gathering.

Bolsonaro -- an ardent admirer of US President Donald Trump with whom he shares a contempt for multilateralism and left-wing ideology -- is under pressure from Brazil's powerful beef, farming and mining sectors to stay on good terms with China, the Latin American country's biggest trade partner.

The far-right leader had threatened to torpedo the relationship during last year's election campaign when he accused China of "buying Brazil," and his pro-business government has been trying to repair the damage ever since.

Speaking to reporters after meeting with Xi and signing largely non-binding agreements on transport, services and investment, Bolsonaro said China was becoming "more and more part of Brazil's future."

Xi echoed the sentiments, expressing hopes for the two countries to "strengthen multilateralism and build an open world economy."

Moscow and Beijing have been major lenders to Caracas in exchange for oil supplies.

Putin met Maduro in Moscow in September, where he reiterated support for his Venezuelan counterpart and called on all sides to end the country's crisis.