The endorsement came after Mr Rajoy's Popular Party (PP) gained the backing of the Ciudadanos ("Citizens") party and tacit support from the Socialists.
Socialist lawmakers are said to have been among the 68 abstentions.
The country had faced the prospect of a third general election inside a year.
But the Socialists forced out their leader, Pedro Sanchez, earlier this month after he rejected abstention.
Mr Rajoy has led a caretaker administration since losing his overall majority in an election last December. A repeat election in June failed to end the impasse but strengthened his hand.
The Socialists (commonly known by their Spanish abbreviation, the PSOE) came second on both occasions, their support eroded by radical leftist newcomers Podemos.
For decades, the PSOE and PP took turns in governing the country on their own but last year the popular vote split four ways - the new centrist Ciudadanos party came fourth.
Spain country profile
The PSOE has 85 seats to the 137 won by the PP in June.
Podemos's Ikea-style appeal to young voters
Resisting change in a dying Spanish village
Taking back Barcelona's apartments

The National Institute for Health and Care Excellence says female patients should have free access to the drug, better known as an anti-wrinkle aid.
Some five million women in England and Wales have urinary incontinence, but many suffer in silence because they are too embarrassed to seek help.
Botox helps control the muscular bladder wall.
NICE says those with "overactive bladder syndrome" that has not responded to recommended lifestyle changes should be offered the injections.
It is not clear what causes it, but those affected by an overactive bladder have a frequent urge to urinate and can experience leakage before they can make it to the toilet.
Cutting down on caffeinated drinks such as tea and coffee, as well as alcohol, doing pelvic floor exercises and making scheduled trips to the toilet can help, but some people will need medical treatment or surgery.
The condition is different to stress incontinence - when the pelvic floor muscles are too weak, as can occur after childbirth, causing leaks with coughing and laughing.
With an overactive bladder, there is a problem with how the bladder responds to getting fuller, meaning the person feels they urgently need to urinate more often than most.
Someone with this condition might end going up to the toilet up to 15 times a day and three times a night, for example, when the norm is to go four to eight times a day and up to once a night.
It affects both sexes, but most often women. The NICE guidelines, which cover England and Wales, only discuss treating women.
Botox treatment is thought to help dampen chemical messages that your bladder uses to tell the brain that you need to urinate.
The injections are administered directly to the bladder wall via a small device inserted into the urethra - the tube you urinate through.
Clinical trials suggest this treatment may last for up to six months, but NICE says people also need to be aware of the possible side-effects.
The treatment can make it more difficult to pass urine and some people may find they need to use a catheter for a time. There is also a chance of getting a urine infection.
Anyone who starts on this treatment should have a face-to-face check up or be reviewed over the phone within four weeks, says NICE.
Prof Mark Baker, director of the Centre for Clinical Practice at NICE, said: "Urinary incontinence is a distressing condition affecting the lives of millions of women of all ages.
"While rarely life-threatening, it may seriously influence a woman's physical, psychological and social wellbeing.
"Over the years we have seen an increase in women seeking treatment, yet many others are still suffering in silence and not receiving the appropriate care for their condition.
"This updated clinical guideline suggests a range of treatments that women should be able to access to limit the distress that urinary incontinence can cause."
Spain's parliament has voted to allow conservative leader Mariano Rajoy to lead a minority government after a 10-month political deadlock following inconclusive elections.
[NEXT_CONCEPT]
Botox injections can now be offered as a treatment for urinary incontinence, says England's NHS drugs watchdog.