Spanish Prime Minister Pedro Sánchez resigned as Socialist Party leader after a snap election defeat that handed dramatic gains to the conservative right — a loss that is being felt far beyond Madrid by the region's fading Marxist movements.