The race is essentially a two-way contest between Susana Diaz and former party leader Pedro Sanchez.
The race is essentially a two-way contest between Susana Diaz, the president of the southern region of Andalusia and former party leader Pedro Sanchez who was ousted in October in a bitter internal rebellion.
Also bidding to head the party is the former president of the Basque Country, Patxi Lopez, but his candidacy has failed to gain traction and he is seen as an outsider.
Nearly 190,000 card-carrying members of the 138-year-old Spanish Socialist Workers' Party (PSOE) are eligible to vote in the leadership primary.
Diaz, 42, a plumber's daughter and career politician, is backed by the bulk of the party's leaders, including two former Socialist prime ministers, Felipe Gonzalez and Jose Luis Rodriguez Zapatero.
She is seen as more amenable to striking deals with the government if she wins the primary while Sanchez, 45, would likely adopt a more adversarial approach that would raise the risk of early elections.
Diaz talks of providing "constructive opposition". After an inconclusive local election in Andalusia in 2015, she made a pact with centre-right Ciudadanos -- Rajoy's allies at the national level -- to reach a parliamentary majority and form a government.
Sanchez on the other hand has been a staunch opponent of Rajoy, deeply critical of corruption scandals impacting the ruling conservative Popular Party (PP) and of their severe austerity measures.
He was forced to resign as Socialist leader in October by high-ranking party members because of his repeated refusal to allow Rajoy to form a minority government following two inconclusive national elections.
Sanchez argues the Socialists must continue in this vein, and move further to the left, to have any hope of winning back voters who have drifted to new far-left party Podemos.
The PSOE "has to be the alternative to the Popular Party," he said Wednesday during an interview with Cadena Ser in which he refused to rule out tabling a no confidence motion in Rajoy if he is chosen.
Rajoy's minority PP government has relied on the Socialists to approve key measures in parliament since it was sworn in for a second term in October.
But if Sanchez takes the helm of the Socialists again, he "will immediately adopt a much more aggressive stance towards the PP in parliament", said Teneo Intelligence analyst Antonio Barroso.
"If Sanchez wins the primaries the risk of early elections over the next 12 months will significantly rise," he added.
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.
He is the preferred candidate of a majority of Socialist voters, 52 percent, according to a poll published in daily newspaper El Mundo on May 14.
Diaz was widely seen as the favourite but figures published earlier this month on the number of endorsements each candidate received from party members indicate the race is closer than expected.
She led the way with 60,000 endorsements, trailed closely by Sanchez who had around 53,000 despite not having the support of party heavyweights. Lopez was a distant third.
Whoever wins the leadership faces a tough job ahead.
Plagued by bad results in general and regional elections in 2015 and 2016, and challenged from the far-left by Podemos, the Socialist party is struggling to rise again and impose itself.
Podemos, led by the charismatic Pablo Iglesias, has become Spain's third most powerful political force and threatens to overtake the Socialists as the main opposition grouping.
"A close result will only make the ongoing split within the party more visible, which will continue to limit the Socialists' electoral potential," said Barroso.