Rajoy, who has led the Popular Party (PP) since 2004, was re-elected at the party's congress, just as far-left upstart Podemos held its own gathering.
No candidate challenged Rajoy's bid to remain at the PP's helm. Defence Minister Maria Dolores de Cospedal meanwhile held on to her position as party deputy.
“We don't want any revolutions or sudden jolts,” Rajoy said, as he put forward his candidacy. “We want to govern with prudence… and reliability.”
Rajoy's popularity sank in 2015 and 2016, as his party was hit by a string of corruption scandals.
At the end of 2015, the PP lost its parliamentary super majority, with the number of MPs falling from 186 to 123 out of 350.
In May 2015, the party also lost a string of important regions, including Valencia in the east, and cities including Madrid.
The PP's losses helped centre-right upstart Ciudadanos make gains, as it condemned the scandals tainting the ruling party.
Ciudadanos has consistently called for Rajoy to step down, refusing to forge any alliance with the PP until he does – even though there is no evidence of Rajoy's involvement in any of the corruption files.
After a months-long political standstill, the PP in June 2016 won a parliamentary election and swept back into power.
Rajoy has been a PP member since 1977, rising through the party ranks until he became prime minister in 2011.
The PP, once named the Popular Alliance, was founded by ministers of former dictator Francisco Franco.
It has since adopted a pro-EU, conservative programme.