The royal family headed by John VI (King of Brazil and Portugal) took refuge there from invading Napoleonic troops.