In 1807, United Kingdom prohibited slave trade in their colonies and pressed Portugal (that had very close relationship with UK) to do the same.
But Brazilian economy depended on slave labor. And land owners weren't having it.
Dom Pedro I declared the independence to calm down the the elite while keeping the country under Portugal influence -- the newly independent country was a monarchy with an imperator from the Portuguese Royal family.
Thanks to him and his son, Brazil was the last country to abolish slavery.
But hey, at least the country didn't break into many small nations. And avoided wars. So in the end it was good I guess \s.