Most of the Greek city-states developed similarly to Athens. Around the year 500 BC, all of Greece felt itself threatened by something external, by a powerful enemy in the east: Persia. The Persians were an equestrian nation, which came out of the rough highlands of the area we today call Iran. They ruled an empire which stretched from India to the Mediterranean coast, and which encompassed the ancient civilizations in Mesopotamia, Palestine, and Egypt. One can truly speak of a world empire in this case.
The Persian emperor (or "king of kings") allowed the subjugated nations to have their religions and customs, but they had to pay tribute (money) regularly, and supply soldiers when the Persian king demanded this of them. In the assembled army, the empire because visible in its expanse, and in successful campaigns, the invincibility of the king showed itself. Because of the great distances and the limited opportunities for direct control, the emperor placed his representatives to rule the individual regions; they were called "satraps" or "tyrants" or governors.
Naturally, the Persian king could not tolerate it, if parts of his kingdom would attempt to gain their independence. But exactly this is what the Greek cities in Asia Minor did, in his opinion, when they undertook a rebellion in 500 BC under the leadership of Miletus. In 494 BC, Miletus was destroyed on his orders.
The Athenians had supported the rebellion. The Persian king Darius sent therefore, in 490 BC, a rather small army across the sea in the direction of Greece. The Athenians didn't want to subjugate themselves, and decided to fight.
In the battle of Marathon, an Athenian army defeated the Persians. A military tactic, not practiced by the Persians, played a decisive role: the Athenians fought as heavily-armed foot soldiers, as "hoplites", and appeared thereby in closed ranks, as a "phalanx". The hoplites, formed in several rows, one after another, were "fired up" by means of music, and followed orders as a unit. If the man in front fell, the one behind him had to step forth immediately. Each one had to rely on the other.
The Persian were not content to be defeated at Marathon. Xerxes, the son of Darius, in 480 BC, undertook for this reason better-prepared attack on all of Greece, with perhaps 100,000 soldiers and approximately 1000 ships.
Many states in northern and middle Greece subjugated themselves, either under threat of force, or voluntarily, but not a confederation led by Sparta and including Athens with its fleet of 200 new battle ships. Sparta was, at that time, the most powerful city-state in Greece, and determined to resist unconditionally.
The first attempt to stop the Persian, at Thermopyle, a narrow pass between the mountains and the sea, gained for 300 Spartans a heroic death, but didn't succeed. The path toward Athens was now open to the Persians. There, the inhabitants left the city, and they hoped for a victory by the fleet. The Persians entered Athens, plundered it, and destroyed the more important temples. They considered this to be revenge for a similar deed by the rebellious Greeks in Asia Minor.
But the war was decided in two large battles. First, the Greeks defeated, with luck and skill, the numerically superior Persian fleet in the straights near the island of Salamis. And in 479 BC, the Persian army was devastatingly defeated by the Spartans and some allies at Plataea. A confederation of Greek city-states had thereby defended its own independence against an empire which appeared incredibly powerful.
In Greece, the opinion now spread about the Persians, that they were not only different than the Greeks, but rather by nature inferior humans. These "Barbarians" were seen as enemies, whom one simultaneously despised and feared. The Greek word "barbar" had, until then, designated someone who did not speak Greek and was thereby unintelligible. After the Greeks used this word on the Persians, it took on the negative connotation which it still has today.