They were already allies, Sparta had sent its army to aid the Athenians ward off the Persian attack in 490 BCE at Marathon (it arrived too late for the battle), and along with the rest of the southern Greek cities, they had a vested interest in uniting to repel the Persian invasion of 480 BCE which was aimed at bringing the Greek cities under local tyrants responsive to Persia.
They had been allies before, and united to help repel the invading Persians. They remained allies until they split over a revolt by the serfs in Spartan territory.
The Persians who was led by Xerxes .
Sparta and Athens were natural allies who provided support to each other - Sparta leading the Dorian bloc of independent city-states, Athens the Ionian bloc, with both interested in maintaining peace. So when a Persian expedition was sent to subdue Athens in 490 BCE after its interference in the Ionian Revolt against Persia, Athens naturally asked Sparta for support (however Athens had defeated the Persians at Marathon by the time the Spartans arrived). When Persia sent a full scale invasion in 480 BCE, the southern Greek city-states united to repel it under the leadership of Sparta with Athens providing the largest naval component. They remained friends and allies until 460 BCE, when Athens sent an army to help the Spartans put down a revolt of its serf population. During this campaign they fell out and avoided each other. After the Persians agreed to peace the Athenians turned the Delian League into an empire of its own, became over-adventurous and clashed openly with the Peloponnesian League led by Sparta, resulting in the 27-year Peloponnesian War which Athens lost.
Self defence.
Pony express
To face a more powerful common enemy
They united 180 Greek city-states into several alliances, the first led by Sparta, the next led by Athens.
Exercising his power of king through his generals.
daa Sparta brought the soldiers ndd the Athens brought theirr navy (:
Athens and Sparta were independent City-States and therefore were not especially close. However, the Greeks did unite to repel foreign invasions. One of the reasons that Sparta and Athens went to war (The peloponnesian war), was because after the city of Athens was destroyed by Persian invaders, the Athenians stole large sums of money from the Delian League to rebuild their city (and also some of their most famous modern wonders, such as the Parthenon), which was a national treasury set up by the primary City-States of Greece. This action enraged the Spartans in particular, and caused the war.
It was in their interests to join with the other Greek city-states in a coalition to defend their mutual interests and cities.
Persian
Some joined the Persians with their armies. A third of the Persian fleet was from Greek cities in Asia Minor. The southern cities united their fleets to fight at Artemesion. They then fought together at Salamis, and the following year at Plataia and Mycale. Then Athens led the Delian league for the next thirty years until a peace was made with Persia.