Spain's Socialist party has appointed its secretary-general as candidate for the post of prime minister in the next general elections due to take place late this year.

The leading opposition party on Sunday tasked Pedro Sanchez with winning back voters and taking on the ruling Popular Party of Prime Minister Mariano Rajoy.

The 43-year-old, who had been chosen as party leader in July 2014, said he aimed to "eradicate unemployment and corruption."

The Socialists, in coalition with radical leftist parties, made advances in recent local elections, and Sanchez will hope to build on that momentum.

Sanchez replaced veteran politician Alfredo Perez Rubalcaba, who stepped down following his party's disastrous results in last year's European Parliament elections.

Sanchez said he would foster growth and create greater opportunities for young people.