Mr Rajoy accepted the mandate but warned he might fail if opposition parties again refused to back him.
His Popular Party (PP) lost its absolute majority in December's election but remains the biggest party.
Most parties have declared they will not back him, including the Socialists under leader Pedro Sanchez.
"We want to change Rajoy's government and this is why we will vote 'no' in a confidence vote," Mr Sanchez said.
Mr Rajoy needs to form a minority or coalition government which must pass a vote of confidence in parliament.
Spain's political turmoil began after the election on 20 December when voters, frustrated with economic crisis and austerity measures, broke the country's traditional two-party dominance.
After the parties filed to agree on a new government, a new election was held on 26 June where, for a second time, no party won an absolute majority.

Detectives realised the scale of the online library after a drugs raid on his home in Pontypridd, Rhondda Cynon Taff.
The 36-year-old Lostprophets singer had encrypted files to cover his trail as a "determined" paedophile.
But experts from GCHQ, the UK government's intelligence headquarters, accessed the files allowing police to present evidence so "overwhelming" that Watkins had no choice but to plead guilty rather than face a trial, says the officer whose team brought him to justice.
South Wales Police Det Ch Insp Peter Doyle revealed that officers recovered a total of 27 terabytes of data storage from computers and devices found in Watkins's possession.
In addition, the "very multi-media and computer savvy" Watkins made extensive use of cloud-based storage to hide his paedophile images from prying eyes.
Watkins had used a reference to child abuse as his password.
On average, one terabyte drive is capable of holding 472 hours of broadcast quality video or 150 hours of high-definition recording.
The 27 terabytes Watkins held dwarfed the data storage held by South Wales Police, which has 2,862 officers and 1,631 support staff.
Watkins has begun a 35-year sentence after admitting 13 offences including the attempted rape of a baby.
His two co-defendants - mothers of the abused children - were also jailed for 14 and 17 years.
He had "furiously denied" the charges before changing his plea at the last minute.
In mitigation, the singer has claimed that his substance misuse had left him with no memory of his "prolific" abuse.
But police say the scale and nature of his online paedophile collection suggests the judge's description of him as "committed and determined" is accurate.
Det Ch Insp Doyle said: "Clearly he was man who used encryption tools. He was a man who went to some lengths to conceal what he was storing.
"He went to some considerable lengths to try and hide his wrongdoing.
"That takes some time to unravel and unfold but unravel it, we did. Which is why we are where we are today."
A link-up with Interpol has led to police following Watkins's trail overseas along the route of Lostprophets tours, he said.
Officers are also liaising with counterparts in the Boston and Los Angeles offices of the US department of homeland security.
He added: "It would be true to say that we have used high-level experts to assist us when it was needed.
"The bottom line is that if we need someone to crack a password for us then people, at a high level, have said 'Yes, we will help you'.
"There is a message there to people. That message is: you can encrypt away as much as you like. But do not think you are safe.
"There are people who will find a way into the device and you will be brought to book."
As Watkins was led away to begin his sentence - 29 years in jail followed by six years on licence - Det Ch Insp Doyle said he could not explain Watkins's change of plea, so avoiding a trial.
He said: "I have no idea why he changed his plea, other than the fact that, in my view as the senior investigator, the evidence against him and the two other paedophiles that were in the dock with him, was absolutely overwhelming."
The King of Spain has asked acting Prime Minister Mariano Rajoy to try to form a  government after the second inconclusive election in six months.
[NEXT_CONCEPT]
Jailed paedophile Ian Watkins was so "tech savvy" his collection of child abuse photos and films amounted to data almost five times the size of the police force that arrested him.