For many reasons the American colonies were unhappy with the Brits, and by 1775 they decided they'd had about enough. At the beginning the rebels did not fare very well, but in October 1777 the winds shifted when a British army surrendered in the famous Saratoga battle. Spain and France got involved and actually did help The United States of America achieve its independence, however it wasn't to the best results of the European countries. The war ended with the Treaty of Paris.
Spain was the biggest loser of the Seven Years War (1763) and saw a golden opportunity for a rematch. France was closely united with Spain as their royal families were closely related. France also saw a chance to beat the Brits and signed an alliance with the settlers and entered into open war with Britain. The settler's troops fought bravely and well, but with little provisions and even less training they would've fared poorly, in all likelihood they would've lost the war if it wasn't for France's help.
Spain was reluctant to enter into direct conflict with Britain, although they immediately supplied the rebels with money and provisions. Their aim was to throw out the British from the Gulf of Mexico and to get them out of their colonies in Central America.
However Spain did declare war on Britain in 1779, after signing a secret agreement with France, the Aranjuez Treaty, in which France agreed to help Spain recuperate a number of territories, including Gibraltar, in exchange for their participation in the war. The Netherlands would also join the coalition later for their own purposes.
In 1779 an intense Spanish siege began but it was unsuccessful. It ended in 1781. In the American territories they campaigned in the Gulf of Mexico that were held by the British and were mostly victorious. Minorca was recuperated by in 1782.
In 1781 a large army of British soldiers was besieged by a French fleet and a Franc-American army led by George Washington in Virginia. After the Yorktown Siege, General Cornwallis surrendered and the British government offered peace
The Treaty of Paris, also know was the Peace of Paris, was signed in 1783., though mainly it referred to Britain and the USA, but they also signed agreements with Spain, France and the Netherlands.
Spain was to keep Menorca and Florida (without clear boundaries, something that would bring further problems later on), it also recovered the territories of Nicaragua, Honduras and Campeche.
The Bahamas Islands, Grenada and Montserrat were returned to Britain (they had been captured by the French and the Spanish). However the British were inflexible when it came to Gibraltar, as they would lose control over the Mediterranean without it. The Spanish immersion in the war is until today little recognized.
The Independence of the United States of America was recognized and they were given all the land north of Florida, south of Canada and east of the Mississipi river. However Britain kept Canada under the empire. France recovered most of the Antilles islands
The Treaty of Paris was ratified by the The American Congress of the Confederation in January 14, 1784.
The outcome was weighed as favourable for Spain al though it wouldn't be much later until their own colonies sought independence.