During the early 5th century BC, Themistokleous, who had created an Athenian fleet of 200 ships, decided to move the port of Athens from Phaleron to Pireas, because Phaleron was too exposed to Athens, while Piraeus was not. Fortifiications for the new port were begun in 493BC and were quite ambitious in scope, intended to include all of the double peninsula and the approaches from Athens. Periklis then ordered a city created near the harbor and consolidated the building of the Long Walls (nicknamed 'the Long Legs' by the Athenians, and which formed a fortified corridor. There were three of them; they were completed in 431 BC (some sixty years later) at the outbreak of the Peloponnesian Wars. One of the conditions for peace offered by Lysander after the defeat of Athens at Aegospotami (405BC) was the destruction of the two remaining Long Walls (the Phaleric wall already having decayed) along with the walls of both cities.
Piraeus' grid plan, still in place in modern times, was the work of Hippodamos of Miletus, a philosopher and geometer. The city was very prosperous for several centuries, doing lively trade in its stoas (porticos). The Romans under Sula sacked the town in 85BC and burned it as well., though it was revived later.
It became known as Porto Leone during medieval times, for the ancient lion statue in front of the harbor entrance which the Venetians carried away, setting it up before their Arsenal in Venice. Pausanius, in the 3rd century AD, described it as a beautiful city (as Athens was similarly described in the late 19th century). The city thrived under Roman and Macedonian rulers, but declined under Turkish rule to the point to being a village of a few hundred inhabitants, and finally, only 50, by the end of the Greek War of Independence in 1935.
It was only after the Greek War of Independence, in the 1830s that the city rose again, growing quite rapidly, its population swelled by immigrants fleeing after the Turkish massacre on the island of Chios; later immigrants came from Hydra, Crete and the Peloponnese. By WWI Pireaus superceded Syros as Greece's main port, a development also furthered by the opening of Suez and Corinth Canals in 1862 and 1893 respectively. The largest population explosion, however, began in 1923 with around 150,000 Asia Minor Greeks settling there (with far greater numbers settling in Athens), this after the compulsory 'population exchange' that followed what is known in Greece as the 'Katastrofi' (catastrophe). The refugees, though Greek, were in general seen and treated as a massive influx of unwelcome foreigners, but the contribution made by some of them to the now immensely popular musical genre known as Rembetika is well known in modern times, since its revival in recent decades. Pireaus was almost totally destroyed in World War II./ The United States' Marshall Plan played a huge role in its recovery afterward.