Since the Anglo Portuguese Treaty from 1373, Portugal was allied with England and other world powers. In 1801 France, governed by Napoleon, wanted to pull Spain into coercing Portugal to break their alliance with the UK and close their port to British ships. There hadn't been a Spanish Portuguese conflict since 1777 when they bickered over borders of their colonies in South America.
There was one problem, however, the Spanish King's daughter Charlotte was married to the future heir to the Portuguese throne and Charles IV, her father, could not go against his son in law. Napoleon reacts by making Maria Louisa, his other daughter, Queen of Etruria, so now it was easier for Spain to get involved as they had signed the Madrid Treaty (1801) which promised the Spanish Immersion in war with Portugal if the Iberian country continued to support England.
Lucien Bonaparte, Napoleon's brother and his ambassador in Spain pressured through diplomacy. Manuel Godoy, the Spanish minister (and Napoleon's ally) advocates in favour of France and the King found his advice hard to ignore. Napoleon's threats were almost explicit, if Spain didn't honour the treaty, then war might as well be against Spain instead of their neighbour. A Spanish Portuguese war was imminent.
So Manuel Godoy gave Portugal an ultimatum: break relations with Britain or face invasion and cede their territory back to Spain. Spain demanded that the British hand them back Gibraltar and Trinity Island, and give Malta back to France. But Portugal refused to submit to Spain's and Napoleon's demands and the stage was set for the so called War of the Oranges.
The military campaign was rather short lived, it took place between May and June of 1801. Manuel Godoy, the Prince of Peace, is named Generalissimo of an army of some 80,000 (French and Spanish) and leads the action. The Spanish troops were divided into three different contingents.
A regiment of some 20,000 men penetrated Portugal through the Miño River under the command of San Simón Marquee, a company of 10,000 through Algarves and the bulk of the troops was lead by Manuel Godoy himself and they crossed Extremadura and entered through Olivenza, which surrendered without putting up a fight. Over the following days after the troops crossed the Portuguese border, they occupied several cities and towns, finding hardly any resistance.
In the city of Elvas the Spaniards ran into some trouble, as the artillery were trenched in the main square. However, the Portuguese King surrendered soon, afraid of having his country invaded by the French. The war's name derives from the Oranges from Elva that Godoy sent to his alleged lover Queen Maria Louisa of Parma (the King's wife). The Spanish Portuguese agreement was set in the Badajoz Treaty, or Peace of Badajoz. It was signed on June 6. Most of the conquests were returned to Portugal except Olivenza and Villareal (Vila Real) a perpetually disputed territory between both Kingdoms, which remain in Spanish hands.
As agreed in the treaty Portugal closed it's ports to England. Although the agreement included the cession of several provinces to Spain to use as exchange currency, Carlos IV ignored this part of the deal, causing the French Emperor deep annoyance. Only 4 years later, after Battle of Trafalgar, England and Portugal's relation was restored.