Fencing descends directly from real swordsmanship and dueling. As firearms ended the sword's role in combat, sword practice survived as a gentleman's art and slowly became a sport, formalized in France, Italy and Hungary through the 18th and 19th centuries.
Each modern weapon traces to a different tradition: the foil was the light practice sword, the épée descends from the dueling sword (first hit anywhere wins), and the sabre comes from the cavalry sword (you can cut as well as thrust). Each keeps its own rules and target area to this day.
Fencing is one of only five sports contested at every modern Olympic Games since Athens 1896. Electric scoring arrived in the 20th century, first for épée, then foil and sabre, replacing the human judges who used to watch for touches. The blades and masks kept getting safer, but the essential game, outthink and outreach your opponent, hasn't changed in centuries.
Curious to try a sport with that kind of lineage? Find a club near you.