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.
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.