In the early 1800s, a bunch of British universities took "football" — a medieval game — and started playing their own versions of it, all under different rules. To standardize things across the country, these games were categorized under different organizations with different names.
One variant of the game you played with your hands became "rugby football." Another variant came to be known as "association football" after the Football Association formed to promote the game in 1863, 15 years after the rules were made at Cambridge.
"Rugby football" became "rugger" for short. "Association football" became "soccer."
After these two sports spread across the Atlantic, Americans invented their own variant of the game that they simply called "football" in the early 1900s.
"Association football" became "soccer" in America, and what was called "gridiron" in Britain became simply "football" in America.