Image caption The world's oldest football was found behind panelling in Stirling Castle

"Organised" football was being played in castle courtyards in Scotland more than 500 years ago, experts have found.

Documents show a set of accounts from the court of King James IV indicating he paid two shillings for a bag of "fut ballis" in April 1497.

The world's oldest surviving football dates back to 1540 and was found behind panelling in Stirling Castle.

The Scottish Football Museum said it appeared the game evolved rather than was invented.

Richard McBrearty, the museum curator, told BBC Radio Scotland's Good Morning Scotland programme it appeared rules were emerging in the 15th and 16th Century, hundreds of years before football was codified at Cambridge University in 1848.

He said: "We know that the game was played in the royal court going back to the 15th Century, 1497, there's accounts of footballs being ordered for the king's court, by the lord high treasurer.

The game's evolved over hundreds of years Richard McBrearty, Scottish Football Museum

"There's fascinating stuff going into the 16th Century, there's a game that Mary Queen of Scots watches in 1568, she's just fled after the Battle of Langside and is at Carlisle Castle.

"A Scottish retinue plays a game for her amusement for two hours and the game's described as being a game of skill, with a little foul play, and the skill is mentioned because of the smallness of the ball.

"The number of players is quite interesting, it mentions specifically 20 players, that suggests a small sided game of 10 in each side."

The first association game in Scotland in 1868 was between Queens Park and The Thistle. It also lasted two hours but was 20-a-side.

"The traditional notion is that in the early 19th Century the modern game is born and that it's almost a revolution, an invention in that respect, we're arguing now from some of the evidence that we're starting to find that really it's an evolution, that the game's evolved over hundreds of years," Mr McBrearty added.

He said there was evidence of structured and skilled games and also of bad tempered players, with one clash even leading to the threat of a duel in the aftermath.