When the Chilean independence movement swept the country, he joined the Royalist side. In 1812, he was named secretary of the New Appeals Court ("Tribunal de Apelaciones"), the body that replaced the colonial Appeals Court ("Real Audiencia"), and later became Minister of the Supreme Court of Justice. Royal Governor Francisco Marcó del Pont appointed him as his secretary in 1815, but after the Battle of Chacabuco put an end to the Royal power in Chile, he went into exile to Lima, Peru where he privately practiced law and became a secretary to the Viceroy. While there he became a widower.