Kyrene was an independent kingdom under Magas, who declared himself king in 276 BCE and kept it so until his death. After his death, the throne was given to Demetrios the Fair, who was the youngest son of Demetrios Poliorketes, as a dowry for marrying his daughter, Berenike II.
Demetrios then began an affair with Apama, the widow of Magas. When Berenike II found out, she killed him and fled to Egypt, where she married Ptolemy III.