In 1793, Portugal and Spain joined the First Coalition against French Republic but Spain dropped out in 1795 after a series of defeats in the War of the Pyrenees. It then allied with France in the 1796 Second Treaty of San Ildefonso and declared war on Britain. During the 1798–1802 War of the Second Coalition, on 20 May 1801 Spain invaded Portugal in the War of the Oranges under pressure from France, which was anxious to deny Britain access to Portuguese ports.