FILE - In this April 26, 2016 file photo, Spain's Socialist Party leader Pedro Sanchez attends a news conference in Madrid, Spain. Spain's Socialist Party has voted against party leader Pedro Sanchez in a special party meeting that sought to end party internal divisions on the country's nine months political blockage. After more than 10 hours of debating, Spain's Socialists are voting for a new general secretary, a decision that could affect the stability of the minority government of conservative Prime Minister Mariano Rajoy. Nearly 190,000 members of the Partido Socialista Obrero Espanol (PSOE) were eligible to choose between former general secretary Pedro Sanchez, Andalusian regional president Susana Diaz or former Basque Country president Patxi Lopez. (AP Photo/Francisco Seco, File)

FILE - In this April 26, 2016 file photo, Spain's Socialist Party leader Pedro Sanchez attends a news conference in Madrid, Spain. Spain's Socialist Party has voted against party leader Pedro Sanchez in a special party meeting that sought to end party internal divisions on the country's nine months political blockage. After more than 10 hours of debating, Spain's Socialists are voting for a new general secretary, a decision that could affect the stability of the minority government of conservative Prime Minister Mariano Rajoy. Nearly 190,000 members of the Partido Socialista Obrero Espanol (PSOE) were eligible to choose between former general secretary Pedro Sanchez, Andalusian regional president Susana Diaz or former Basque Country president Patxi Lopez. (AP Photo/Francisco Seco, File)

BARCELONA, Spain (AP) — Spain’s Socialists voted to put Pedro Sanchez back in charge as their general secretary on Sunday, seven months after party heavyweights ousted him from power.

In a stunning blow to the old guard of the Partido Socialista Obrero Espanol (PSOE), Sanchez won 50 percent of the over 148,000 ballots, beating main rival Susana Diaz who received 40 percent despite the backing of most of the party’s leaders. A third candidate, Patxi Lopez, got 10 percent.

As the final votes were counted, a group of Sanchez supporters gathered in front of the PSOE headquarters in Madrid and chanted “Pedro! Pedro! Pedro!”

ADVERTISEMENT

Sanchez’s return to the leadership of the second-largest party in Spain’s Parliament means that Prime Minister Mariano Rajoy will likely have a tougher time keeping his minority government afloat.

“What the prime minister of this country fears is a unified PSOE and that is what we are going to have starting tomorrow,” Sanchez said. “We are going to carry out this mandate of the ballot box and build a PSOE that is of its members and voters. This will be a PSOE of the Left.”

Sanchez will also be at odds with most of PSOE’s regional leaders, who forced him to resign as general secretary in October after disagreeing with his opposition to Rajoy forming a government.

The PSOE’s caretaker board which took over following Sanchez’s resignation has shown more willingness to support some initiatives of Rajoy’s conservatives in parliament.

The removal of Sanchez and permitting Rajoy to stay in power enraged a large segment of the PSOE’s voters, and eventually paved the way for him to return to power.

While Sanchez said he won’t support a no-confidence vote against Rajoy soon to be brought to parliament by the far-left Podemos party, he has said he may present his own no-confidence vote if there are more cases of corruption involving Rajoy’s Popular Party.

“The PSOE is going to do whatever it takes to change the course of this country, to end the corruption of the Popular Party and make the lives of our children better,” Sanchez said after shaking hands with Diaz and Lopez.

Founded in 1879, the PSOE is Spain’s oldest political party. It led Spain from the isolation of the dictatorship of Francisco Franco into the European Union. But, like many of Europe’s traditional parties, it has suffered big losses since governing at the start of the recent economic crisis and the emergence of new anti-establishment parties.

ADVERTISEMENT

In last June’s general election, the Sanchez-led Socialists had their worst results since the return of democracy in the late 1970s, as Podemos and the upstart center-right Citizens cut into their base.

Diaz, who governs the PSOE’s southern stronghold of Andalusia, had the backing of former Spanish prime ministers Felipe Gonzalez and Jose Luis Rodriguez Zapatero in her bid to become the first woman to lead the party.

The 45-year-old Sanchez, a basketball player in his youth, will now have the daunting challenge of mending a party sharply divided.

Moments after he was reelected, the PSOE’s spokesperson in the parliament, Antonio Hernando, announced he was renouncing his post.

Sanchez won’t officially take power until the party congress on June 17-18. Until then, the caretaker board headed by Javier Fernandez will remain in charge.