Ulloa returned to South America in 1758 as governor of Huancavelica, in Peru, and general manager of the quicksilver mines in the region.  At the time, quicksilver (mercury) was of great practical importance because of its use in the extraction of silver and gold.  Ulloa fought unsuccessfully against the deep-rooted corruption in the local administration and finally requested to be relieved of his post in 1764.
Following the defeat of France by Britain in the Seven Years War, France agreed in the secret Treaty of Fontainebleau to cede to Spain its remaining territories in North America.  The Spanish Crown then appointed Ulloa as the first governor of Spanish Louisiana.  Ulloa reached New Orleans, the major city and port of the region, on 5 March 1766. The French Creole colonists refused to recognize Spanish rule, leading to the Louisiana Rebellion of 1768. On 28 October, as riots broke out in New Orleans, the governor and his pregnant wife were taken to a Spanish vessel.  The Superior Council voted that the governor leave within three days. He complied, departing on 1 November. The revolt was ultimately crushed in 1769 by forces under the command of the new Spanish governor, Alejandro OReilly, who succeeded in establishing definitively the control of the region by the Spanish Crown.
Between 1776 and 1778, in the context of the American Revolutionary War, in which Spain supported the fight against British rule of the Thirteen Colonies, Ulloa helped organize a fleet of the Viceroyalty of New Spain (present-day Mexico) and construction of a military shipyard in the Atlantic port of Veracruz.  He was in command of the last great naval fleet to sail from Cádiz to the Americas.