"There are no red lines or lines of any other colour" on Gibraltar, Rajoy said at a news conference after 27 European Union leaders met without Britain to adopt their negotiating position for Brexit talks.
The EU 27 guidelines state that "no agreement" after Brexit between the EU and Britain could apply to Gibraltar without a bilateral agreement between Madrid and London.
Britain has expressed alarm over the clause and British Prime Minister Theresa May has insisted she will "never" allow Gibraltar to slip from British control.
In a statement, Gibraltar's leader Fabian Picardo said the treatment called for in the clause "is discriminatory and unfair" and goes against "the principle of sincere cooperation which the EU is committed to."
Gibraltar, he said, stood "clear and united" against any Spanish government attempts to "advance its stale sovereignty claim" even if the British outcrop will continue seeking dialogue with Spain.
"Our future beyond the EU will be a prosperous and international one in respect of which the Spanish government will have no say or veto," Picardo said.
With a population of just over 32,000, Gibraltar has been a British overseas territory since 1713 but Spain has long laid claim to it. Some 10,000 people cross from Spain to Gibraltar to work every day.
Authorities in Gibraltar fear Spain is trying to take advantage of Brexit to impose its control over the territory.
One former leader in May's Conservative party said the dust-up invoked the memory of the Falklands War against Argentina.
Gibraltarians voted overwhelmingly to remain in the EU in last June's Brexit referendum, but they still appear set on remaining British after the vote.