Cameron had been due to address a pro-EU rally in the British overseas territory last week as he campaigned to remain in the 28-member bloc ahead of Thursday's referendum, but was forced to cancel and return home after the murder of MP Jo Cox.
Instead, he recorded a statement that was aired on Tuesday on television in Gibraltar, which fears that a Brexit would leave it at the mercy of Spain and damage a thriving economy that relies in large part on access to the EU's single market.
“I believe we'll be stronger, we'll be safer, we'll be better off if we stay,” Cameron said.
“I wanted to come to Gibraltar to make the speech in Gibraltar because it should remind Britain of our wider responsibility and our wider role in making this argument.”
He also pledged to stand up for Gibraltar – a long-time source of friction between London and Madrid, with Spain wanting Gilbraltar to come back under Spanish control centuries after it was ceded to Britain in 1713.
Cameron's planned trip had drawn huge excitement in the tiny rocky outcrop on the southern tip of Spain, where the last serving British prime minister to visit was Harold Wilson in 1968.
A tweet from Gibraltar's Chief Minister:
A true friend of Gibraltar and a GREAT advocate for REMAIN and for The Rock! https://t.co/1yoWxZB8Gi
— Fabian Picardo (@FabianPicardo) June 19, 2016
But it also drew anger from Spain, with Prime Minister Mariano Rajoy telling Cameron to stay in Britain for his campaign.
Gibraltar chief Fabian Picardo has said he is worried Spain may seize the opportunity of a Brexit – which would leave it without EU protection – to threaten the land border between the two, a long-time flashpoint in the sovereignty row.