Sanchez, a former economics professor ousted in a messy internal rebellion last October, comfortably beat two rivals in a poll of party members, taking 50 per cent of the vote, partial results with 90 per cent of ballots counted showed.
His nearest rival, Andalusian regional president Susana Diaz who was backed by the bulk of the party's leaders and was seen as more amenable to striking deals with the government, took 40 per cent.
Sanchez was forced to resign over his staunch refusal to allow Prime Minister Mariano Rajoy and his Popular Party (PP) to form a minority government following two inconclusive general elections.
Diaz and the other architects of the rebellion argued it was best to let a PP government through rather than go to the third elections in a year and risk losing even more votes.
More From This Section
Sanchez called this a huge mistake and he was deeply critical of corruption scandals impacting the PP, and of their severe austerity measures.
Rajoy has relied on the Socialists -- who have been led by an interim leadership since Sanchez was ousted -- to pass key measures in parliament since he was sworn in for a second term in October.
But analysts said Sanchez would have a more tense relationship with the government and the risk of snap elections would increase with him in charge of the Socialists again.
"At a minimum, therefore, a Sanchez-led PSOE would make parliamentary politics more challenging, and reduce the already limited space for economic reform," Eurasia Group analyst Federico Santi said.
Much like Britain's Labour party leader Jeremy Corbyn, who survived a leadership challenge last year but still faces internal dissent, Sanchez enjoys considerable support among grassroots Socialist activists even though he is opposed by party heavyweights.
"Party members are with Pedro," Juan Jose Orts, a party member since 1974, told AFP as he celebrated Sanchez's win outside PSOE headquarters in Madrid with dozens of other supporters.
"This is where he was killed and this is where he was resuscitated."
The audiences at rallies for Sanchez and his rivals in the leadership race were mainly middle-aged or older, highlighting the party's struggle to appeal to younger voters.