Many ball sports are types of “football”. Soccer is derived from “association football” while American (and Canadian) football is derived from “gridiron football”.
Many different ball sports have historically been given the name football. In an effort to clarify things, the Football Association in England defined a set of rules in 1863. Both rugby and soccer were called football, so they got split into “Rugby football” and the “association football”.
Linguistically creative students at the University of Oxford in the 1880s distinguished between the sports of “rugger” (rugby football) and “assoccer” (association football). The latter term was further shortened to “soccer” (sometimes spelled “socker”), and the name quickly spread beyond the campus.
Around the beginning of the 20th century, another game of football arose in America called “gridiron football”. Football became the preferred way of describing this American form of football, and to distinguish it from association football, that form was better known as “soccer”.
Interestingly, we’re generally led to believe that calling the game soccer is wrong because “the rest of the world” calls it football. However, it appears that for a significant time in Britain, both soccer and football were used interchangeably. The usage of the word soccer declined only when it became more closely associated with “soccer” in America.