Soldiers from the island fought under the Spanish flag against Bernardo O'Higgins , Chile 's national hero , and Chilean history textbooks describe it as Spain 's last outpost in South America , from which it was expelled only in 1826 .