The intervention in Spain started well for the pro-Habsburg side, with the capture of Gibraltar in 1704 and Barcelona in 1705 and securing the support of Portugal and the Catalans. However, it soon became clear the Bourbon candidate Philip V was far more popular in Castile than the Austrian Archduke Charles. The Allies were forced to evacuate Madrid in 1706 and soundly beaten at the Battle of Almanza in 1707.