Spain, which betrayed Portugal in 1807 (its ally until then) to ally with France, saw himself betrayed by Napoleon, whom imprisoned the Spanish royal family and nominated his brother, José Bonaparte, as King of Spain, title unrecognized by the population which resisted the French occupation.