The legend is that William Webb Ellis picked up a soccer ball and ran with it at the Rugby school in the early 1800's. Soccer was around a long time before rugby came on the scene.
American football is a direct descendant of rugby, but I believe the main influence was Rugby League. League was the original professional version of rugby. It has rules that are much closer to American football (six downs, a line of scrimmage, etc).
Link: https://en.wikipedia.org/wiki/William_Webb_Ellis