The differences between Sparta and Athens didn't stand in the way of a confederation, when the Persian empire threatened them. But after the victories at Salamis and Plataea, Sparta did not join the Athenian maritime federation. The Spartan warriors were too intent on not endangering their position of power on the Peloponnesian peninsula. They had there not only subjugated the Messenians, but also forced most of the other city-states into cooperation in the Peloponnesian league. Sparta and Athens both had now brought a large number of city-states behind them, and competed for the hegemony in Greece.
Starting in 431 BC, the two powers led war against each other. Because Athens had the strong fleet and much money, Pericles and most of the Athenians thought that they could attain the ultimate hegemony in Greece. The Spartans had neither a fleet nor money, but announced an inflammatory goal for their war: all Greeks should be free and independent - specifically from the oppressive Athenian mastery over the maritime confederation. Because both sides had many allies, and wanted to win unconditionally, almost all Greeks were soon enveloped in a long and bloody struggle. Finally, the Spartans even worked with the Persians, in order to build a fleet also. Athens was weakened, as shortly after the war's beginning, many people died of a plague. After that, victories and defeats alternated. Finally, Sparta defeated Athens at sea. The city was starved, and had to surrender in 404 BC.
But it became clear in the next century that actually both powers had lost. Sparta could maintain its new leadership position in Greece only with violence, and even then not continuously. The continuous oppression of the majority of the inhabitants in their city weakened the Spartans too much. And even democratic Athens could not win its old power back again.