The Persian king Cambyses II conquered Egypt in 525 BC. Libyans attacked from the east, but the Persians fought them off. After the Greek victory at Marathon in 490 BC, the Egyptians revolted against the Persians (in 484 and again in 460 BC) with the help of the Athenians, but unsuccessfully.
Later Persian kings were not as strong, and in 404 BC Egypt succeeded in becoming independent. The new Pharaohs established Dynasties 28, 29 and 30. Dynasty 28 was very short (only one Pharaoh!). In Dynasty 29, the Egyptians made an alliance with the Greek city of Sparta where Sparta would help Egypt against the Persians in exchange for a lot of wheat, but unfortunately the Persians captured the Egyptian wheat ships on their way to Sparta, so that didn’t work out very well. (The Egyptians were dealing with the Spartans now instead of the Athenians because Athens was weaker after the Peloponnesian War).
The Pharaohs of Dynasty 30 tried to re-establish Egypt as an independent country. They fought off Persian invasions. One time, the Persians had to go home because the Nile flooded when they were trying to invade. Like earlier Pharaohs, the Pharaohs of Dynasty 30 made alliances with Sparta and Athens and other Greek cities to try to keep off the Persians. Some of the Pharaohs even tried to put the New Kingdom back together by invading Syria.
But in the end the Egyptian pharaohs couldn’t keep fighting the Persians off. After sixty-three years, the Persians reconquered Egypt in 341 BC. But the Persians didn’t keep Egypt very long. Nine years later, in 332 BC, Alexander the Great conquered Egypt as part of his takeover of the Persian Empire. Here he is on the walls of a temple at Luxor, carved in an Egyptian style.
Bibliography and further reading about Egypt under Persian rule:
Eyewitness: Ancient Egypt, by George Hart. Easy reading.
The Oxford History of Ancient Egypt, by Ian Shaw (2002).
History of Ancient Egypt: An Introduction, by Erik Hornung (1999). A college textbook. On the conservative side – not much on new developments.