Codro (Latin: Codrus), in Greek mythology, was the last king of Athens, son of Melanto, he reigned for twenty-one (21) years, from 1090 to 1069 BC.
According to Pausanias, when the Heraclites took the Peloponnese, Melanto, along with other exiles, went to Athens, and there overthrew Timetes, becoming king. According to the Byzantine text Suda, there was a border conflict between Athens and Beotia. Xanthus challenged Timetes to a duel, who did not accept; but Melanthus agreed to fight for Athens. Melanto used a dirty trick, and killed Xanthus.
Melanto's successor was his son Codro, the last king of Athens.
During his reign the Ionians were driven out of Achaia (1085 BC) and took refuge in Athens.
He reigned during the Dorian invasions, and sacrificed himself to save Athens: the Oracle of Delphi had predicted that the Heraclids would conquer Athens if their king was not killed, so he disguised himself, provoked the invaders, and was killed by them. Athens abolished the title of king and became ruled by archons, the first being Medon, son of Codro.
In Athens, until the death of Codro, there were two important magistrates: the basileus (king) and the polemarch,the commander of the military forces. With Medon, the office of archon was introduced, initially for life, but later changed to a ten-year term; some historians, however, consider that the office of archon was instituted with Acastus, Medon's son.