The results marked the worst defeat for Erdoğan and his AK Party (AKP) in their more than two decades in power.