The Socialists of Spanish Prime Minister Pedro Sánchez have won Catalonia's regional election as pro-independence parties lost ground.