Pedro Sanchez resigned after losing a party assembly vote, a step which could pave the way for the formation of a new government.