Background
Persia had recently begun their invasion of Greece in 499 BC. Led by Darius The Great, the third emperor of the Persian Empire, he had wanted to expand his land. Recently, there had been something called the Ionian Revolt, where the region of Ionia, in modern-day Turkey, revolted against the Persian Empire. Persia soundly defeated the revolt, but Darius was afraid that other civilizations would revolt against them. So, Darius decided that he wanted to subjugate all of Greece and the Aegean (city-states in the Aegean Sea), and to punish all involved in the Ionian Revolt, including Athens.
During the Ionian Revolt, Athens and another Greek city-state Eretria (not to be confused with Eritrea) burned and looted the city of Sardis, gaining the lasting animosity of Darius. He vowed to get them back, and after the Ionian Revolt had finally been defeated, he began an expedition to Greece. Persia reconquered Thrace, and destroyed Eretria. Darius was still set on destroying Athens. According to Herodotus, he had a servant say to him at every meal "Remember the Athenians." Finally, in August/September 490 BC, the Battle of Marathon, which sought to take over Athens, would begin.
Battle
Searching for Aid
Before the battle began, Athens came to Sparta for support, as they had an extremely powerful army. Athens sent Pheidippides to run to Sparta and ask for the Spartan army's aid. However, Sparta was in observance of the festival of Carneia, a period of peace. That meant that Sparta would not fight Persia. Plataea, a nearby city-state offered 1,000 troops to Athens, a gesture that would be greatly appreciated and won the gratitude of Athens for many years.
Setup
Persia had come by boat, and they landed at the bay of Marathon, 40 km from Athens. Militiades, the Athenian general, had ordered his troops to quickly block off the Persians, preventing them from coming inland. For five days, they were stuck in a stalemate. Neither side was attacking, and they both were hesitant to initiate the conflict. Athens had ten strategoi, or generals, and they were to decide whether attack or wait. They voted, and it resulted in a 5-5 tie. In charge of the strategoi was Callimachus, and he had the decisive vote on the matter. Militiades, the Athenian general, really wanted to attack, and he convinced Callimachus to vote yes. Sure enough, Callimachus voted yes, and Athens was going to attack.
Conflict
The distance between Persia and Athens had shortened to 1.5 km, and Militiades ordered Athens to attack. He split their army up into two tribes, with one going to the left and the other going to the right. The Athenians marched until they were 200 m away, and the archers started shooting, while the hoplites (soldiers) charged the Persians. The Persians had expected an easy battle, but Athens were excellent swordsmen and soldiers. They quickly routed the Persian army, and they retreated quickly. Herodotus estimates that 6,400 Persian soldiers died, while only 192 Athenians and 11 Plateans were killed.
Legend of the Marathon run
This would not be complete without the story of Pheidippides and his famous run. The legend states that a messenger, named Pheidippides of Phillipides was sent from Marathon to Athens to deliver the news that Athens had won. He was so exuberant, he ran the 25 miles (40 km), and once he arrived, he yelled "nenikekamen!" ("We have won!") before collapsing and dying. This run became famous, and now the marathon is named after that run. It's important to note that this story most likely isn't historically accurate. Herodotus, a famous historian who wrote extensively about this battle, did not mention a runner from Marathon to Athens.
Aftermath
Immediately after retreating, Persia wanted to attack Athens directly. They began to sail up to Athens. Athenians arrived in time to prevent Persia from landing, so they gave up and went back to Asia. Persia would be gone for the next ten years.
Although they would be gone for now, Persia was assembling a massive army that was going to subjugate all of Greece. In the meantime, Egypt revolted, halting their plans, and while preparing to stop the Egyptian revolt, Darius died, and the throne was passed on to his son Xerxes I. He destroyed the Egyptian revolt, and was ready to take on Greece. In 480 BC, ten years after the Battle of Marathon expelled the Persians, they would come back to fight the Battle of Thermopylae and attempt to take over all of Greece.