A close ally of Turkish President Recep Tayyip Erdogan has been elected new leader of the ruling AK Party and prime minister.