Nearly two centuries after it was cut from his corpse and stashed in formaldehyde, the heart of Emperor Pedro I, who declared Brazil's independence from Portugal, returned for politically charged commemorations of the South American nation's 200th birthday.

Dom Pedro, a beloved figure in both Brazilian and Portuguese history, has been divided between the two countries in death.

His heart has been enshrined in a church in Porto, Portugal, and the rest of his remains in an independence monument in Sao Paulo, Brazil.

But after Porto city officials agreed to return the heart on loan, it arrived in Brazil for the country's bicentennial independence celebrations on 7 September.

The heart, which is kept in a glass jar in a golden urn, arrived with all the pomp and circumstance of a state visit.

"It will be treated as if Dom Pedro I were alive and with us ... just as if it were a state visit by a foreign leader," said Alan Coelho, chief of ceremonial protocol at the Brazilian foreign ministry.

Dom Pedro fled to Brazil with his family as a nine-year-old boy when Napoleon's army invaded Portugal in 1807.

He stayed behind to rule the then-colony as regent when his father, King Joao VI, returned home to the increasingly restless mother country in 1821.

Facing pressure to rein in the political autonomy the colony had enjoyed, Pedro I instead declared it an independent country on 7 September 1822, and became its first emperor.

Pedro I of Brazil

But no sooner had he thrown off Portuguese rule and established Brazil as a constitutional empire than turbulence across the Atlantic forced him to return to Portugal, where his younger brother had usurped the throne and was attempting to return the country from a constitutional government to absolute monarchy.

Pedro I, who is known in Portugal as Pedro IV, abdicated in 1831 and sailed back to Portugal, leading an army into Porto in support of the constitutionalists' ultimately successful struggle.

After his death of tuberculosis in 1834, he was celebrated in both Brazil and Portugal as a champion of liberal causes and representative rule.

At his request, his heart was removed and kept in Porto, in gratitude to its people for their support.

"Today the heart of this national hero, the first emperor of Brazil, returns home to our soil," Defence Minister Paulo Sergio Nogueira said at a ceremony to welcome the organ at an air base in Brasilia.

"This important relic represents the bravery, passion and above all the immeasurable strength of our first emperor."

The heart has a busy agenda for its visit. President Jair Bolsonaro will hold an official ceremony for it with military honours.

The 9kg urn will then go on display for 17 days at the foreign ministry headquarters, Itamaraty Palace.

Mr Bolsonaro, who is campaigning to win re-election in October, has faced accusations of fanning the flames of nationalism with the festivities around the heart.

The far-right leader is also planning a big rally by supporters and a military parade on independence day.

Critics said parading the heart around was reminiscent of when Brazil's 1964-1985 military dictatorship, which Mr Bolsonaro openly admires, brought the rest of Pedro I's body back from Portugal in 1972.

"This is going to be a farce by Bolsonaro, welcoming this heart like a visiting dignitary," said historian Lilia Schwarcz, who has written books on Pedro I and Brazilian independence.

"We should ask ourselves what kind of way this is to think about history - a dead history stuck in time, like the stopped organ of a deceased emperor."

Kept under quintuple lock and key at the Our Lady of Lapa church in Porto, the heart will be under the watchful eye of a police officer sent by the Portuguese city, before being returned on 8 September.