"I am absolutely convinced that we will reach an agreement so that these people will not be affected by political decisions," Rajoy told AFP in an interview this week.
Up to one million Britons are estimated to be living in Spain, many of them pensioners enjoying sunnier climes.
They currently receive healthcare coverage under EU mechanisms that give them the same treatment as locals, but this access could become prohibitively expensive once Britain leaves the EU.
He said the negotiations would start after an EU summit that will convene once Britain formally begins its EU divorce proceedings, expected for the end of March.
More From This Section
He also noted the importance of British tourism to his country, which attracts more visitors from Britain than any other country.
"Last year 17 million Britons came to Spain, and we want that to continue," he said. "They like it, and so do we."
"We are going to ask that all decisions affecting Gibraltar be made bilaterally between the United Kingdom and Spain," he said.
Madrid has recently offered dual citizenship to Gibraltarians in exchange for joint sovereignty of the territory, which offers strategic control of access to the Mediterranean.
"I think that our proposal of shared sovereignty is quite reasonable," Rajoy said -- although both London and the government of Gibraltar have rejected the idea.