in Algiers. He benefited from the third Pacte de Famille (1761), which allowed Frenchmen to take part in Spanish military campaigns with equal rights and requirements as the Spaniards. At the campaign's conclusion, Liniers took an exam as a Midshipman in Cádiz, to serve as a volunteer for the Spanish Crown. In 1775 he earned the rank of Ensign in the Spanish Navy. In 1776, under the orders of Pedro de Cevallos, Liniers sailed to the Viceroyalty of the Río de la Plata and took part on the occupation of Santa Catarina Island in Portuguese Brazil and the attack on Colonia del Sacramento (modern day Uruguay). In 1779, Liniers was an officer on the San Vicente. Spain joined the Franco-American alliance in the American Revolutionary War as a renewal of the Bourbon Family Compact. The San Vicente was part of the Spanish-French naval squadron fighting against the Royal Navy in South America. Liniers distinguished himself during the American Revolution. In 1780, with a few sloops, he captured a three-masted ship of 24 guns. In 1782, he distinguished himself particularly in the siege of Port Mahon: under fire, he moved to where two British ships had collided, which were laden with arms and ammunition. He captured the ships and conveyed them to the Spanish lines. He was promoted to Frigate Captain. A few months later Liniers took part in a new expedition, this time against the city of Algiers, in North Africa, which was the main base of the Barbary corsairs, with the aim of forcing them to stop piracy and the Barbary slave trade. As the campaign did not go well for the Spanish navy, Madrid tried to negotiate instead. Liniers was entrusted with this mission. The king of Tripoli was delighted with Liniers, and agreed to free several European prisoners. The Barbary pirates associated with North Africa had long been attacking European shipping in the Mediterranean, and had taken numerous prisoners over the years. The Spanish court rewarded Liniers for this diplomatic success, promoting him to the rank of captain and entrusting him with the command of the Río de la Plata in 1788 to organize a flotilla of gunships. Liniers took with him his son Luis and his first wife, Juana de Menviel, whom he had married in Málaga. She died two years later in 1790. Liniers married again, this time in Buenos Aires, to María Martina Sarratea,