Actually, it was only Brazil's 2nd emperor, but Pedro II did have a 49 year reign. He was a good leader, and the economy grew and people prospered under him. Until he alienated certain sects of society (think the military and growing urban middle class). So the military decided they'd do a better job ruling than he would.
Pedro left for Europe and died in exile 2 years later.
There's actually more to it than that, and a very interesting story with Portugal's crown prince, Don Pedro, declaring Brazil an independent country under his rule. But he was a lousy ruler, and Portugal was probably lucky he wasn't their leader. Pedro I abdicated in favor of his 5 year-old-son. Who, it turned out at age 15, didn't inherit his father's bad-ruler genes.