These battles were part of the wars between the Persians and the Greeks. The Greeks had been expanding their power and had put some colonies across the Aegean in Asia Minor. These colonies brought them into conflict with the Persian Empire, which dominated that area of Asia. Those colonies came under Persian control but then rebelled against Persia in 499 BCE. The Persians crushed the rebellion and then decided to move against Greece itself.
It was in this context that the battles you mention happened. The battle at Marathon blunted the first Persian attack, at which point the Persians did not invade again for years. In 480 BCE, though, they attacked again. The Spartans held their advance for a while by sacrificing themselves at Thermopylae. The naval battle at Salamis was a decisive Greek win and the Persians withdrew again.