When John ascended the throne, he found himself entangled in the War of the Spanish Succession, as King Pedro II had signed the Methuen Treaty in 1703, which aligned Portugal to the Grand Alliance against the House of Bourbon and allowed Grand Alliance forces to launch their invasion of Spain from Portugal. Only months after assuming the throne, John saw his forces overwhelmingly defeated in at the Battle of Almansa, a defeat that jeopardized Portuguese forces in Spain and the outcome of the war. Portuguese forces continued to fight alongside the Grand Alliance until agreeing to an armistice with Spain and France on 8 November 1712. The war finally came to an end in 1713 with the signing of the Treaty of Utrecht, whereby Portugal regained possession of territories conquered by the Bourbon coalition and acquired new territories in South America.