He will leave immediately as head of his party and will resign as prime minister after a new party leader is chosen.