In a press conference, Rajoy said King Felipe VI had asked him if he would attempt to form a government, adding he had "accepted this assignment."
The country has been without a fully-functioning government since elections on December 20 failed to give any party an absolute parliamentary majority, as upstarts Ciudadanos and Podemos shook up Spain's long-established two-party system.
Efforts to forge a coalition were subsequently unsuccessful as rival parties were unable to overcome their differences, prompting repeat elections in June with a similar result.
Although its victory margin was wider than in the December polls, the conservative party still failed to achieve an absolute majority.
Also Read
Rajoy needs to get enough support from other parties to push a coalition or minority government through a parliamentary vote of confidence -- be it with ballots in favour or abstentions.
But he faces an uphill challenge, as most other political parties have already announced they will not back him.
If he fails, Spain will most likely have to hold a third round of elections.