History Fencing is a sport pretty much as old as civilization. Using "fenced" or blunted weapons to safely train for combat is documented in ancient Egypt. It probably started with them like it did with most of us whacking each other with sticks.
Classical Fencing Classical fencing, or what we typically think of as fencing, with rapiers and sabers, swashbuckling and such grew out of the dueling traditions of the 15th century.
Modern Fencing Modern Fencing, Sport Fencing or Olympic Fencing is constantly evolving but is first documented in the 1700s. Fencing has been present since the first Olympic Games in 1896 and is the only sport to have been included in every games ever since.
All the geeky details are on the Wikipedia Page... no need for me to list them all here
Is Fencing Safe? Modern Sport Fencing is a very safe sport. In terms of injury that will keep an athlete from competing, fencing is really very low in comparison to other Olympic sports. This infographic from Scientific American Relative Frequency of Injury shows the relative safety of the sport.
That isn't to say that the sport is pain free. There can be a sting from a hard hit and some bruising (more so in epee and saber than foil). Serious injuries are rare.