To understand the history behind the exact distance of the marathon, first let’s see briefly the history of the marathon race itself.
According to a legend, Philippides or Pheidippides, the Greek messenger was sent from the battlefield of Marathon to Athens to announce that the Persians had been defeated in the Battle of Marathon (490 BC).
According to the legend, Pheidippides, after having fought himself in the race, run the entire distance without stopping.
The idea of the marathon race was born right before the first modern day Olympics, in 1896. It was used to popularize the event, recalling the ancient glory of Greece.
The distance between the battlefield of Marathon and Athens is approximately 40 kilometers (depending which route Pheidippides might have been taking), and this was the distance of the first Marathon event in the 1896 Olympic Games.
There was no established distance in the following decade, each orgainzer deciding upon the exact length, according local conditions.
The International Olympic Committee agreed in 1907 that the distance for the 1908 London Olympic marathon would be about 25 miles or 40 kilometers. The organizers decided on a course of 26 miles from the start at Windsor Castle to the royal entrance to the White City Stadium, followed by a lap (586 yards 2 feet; 536 m) of the track, finishing in front of the Royal Box. The course was later altered to use a different entrance to the stadium, followed by a partial lap of 385 yards to the same finish.
The modern 42.195 km standard distance for the marathon was set by the International Amateur Athletic Federation (IAAF) later in May 1921 from the length used at the 1908 Summer Olympics in London.
In this interactive Google map you can see the modern day distance between the battlefield of Marathon and the Acropolis in Athens.
Here you can find the marathon distance in different measuring units:
Sources: Wikipedia Marathon Race and Marathon, Greece articles.