Brazil was elevated to a Kingdom in the United Kingdom of Portugal, Brazil and Algarves in 1815 after the king of Portugal fled europe and moved himself, his court and his capital to Rio de Janeiro, which became capital of the empire.
After Napoleon was defeated the portuguese started getting uppity and had a liberal revolution demanding the king would come back to Portugal, where they would cuck him out of his kingly rights and force a liberal constitution on him.
After some deliberation, the king returned, but he left his son Pedro (who moved to Brazil as a child) behind. The courts got mad and demanded everyone go back to europe, including Pedro (now acting as prince regent of Brazil) and his wife Leopoldina (a Habsburg).
He said he would not and declared Brazil an independent empire (his father had advised him to do so if necessary, before some republicuck did it), so in 1822 Brazil became an independent monarchy, being recognized by the UK, the US, etc after a brief war against the troops of the portuguese parliament (a minority in brazil supported parliament, most supported the king, which had done more for the country than p*rliament ever could).
After some troubles, the king died and Pedro I was next in line to be king of Portugal too, but since no one wanted the two countries to reunite he resigned the portuguese throne (where he was Pedro IV) in favor of his daughter, putting his brother as regent.
His brother promptly cucked his daughter and declared himself King of Portugal, and after some troubles in Brazil (starting soon after independence, including him cucking liberals who wanted to write a constitution to make him nothing a powerless king like Liz is today, and then writing a constitution himself) Pedro resigned his throne in favor of his son, Pedro (which became Pedro II of Brazil).
Pedro I moved back to Portugal and fought his brother in a civil war, defeating him and guaranteeing both thrones to his children, then he died.