Last night's visit was the first time Shetland has seen a prime minister in 34 years, following the visit of Margaret Thatcher in 1980. Her Tory predecessor Ted Heath was the first to visit the islands in the 1970s.
Mr Cameron feels it is important to set out the Government's long-term economic plan and the case for the union in every part of the country, a Number 10 spokesman said.
The PM visited the Bristow search and rescue team before taking in a local landmark and meeting residents in the town hall in Lerwick.
The Prime Minister told Shetlanders that the UK Government has reached a deal to spread the subsidy costs of providing electricity to the Shetlands across the whole of Great Britain, and not just the north of Scotland, putting the subsidy on a more sustainable, long-term footing.
This will keep prices at 75% less than they otherwise would be, according to Number 10.
That is £1,200 lower than the average domestic bill would be without the subsidy and also means lower bills for those in northern Scotland who have, until now, footed the whole subsidy cost, the spokesman said.
This will save the average northern Scottish consumer around £42 a year, he added.
The subsidy is worth an average £20,000 to medium-sized non-domestic properties such as schools and hospitals, and £180,000 to large non-domestics such as fisheries.
The announcement follows a previous UK Government announcement that Shetland's power plant, built in 1954, will be replaced in 2017 with a new one, with a commitment to helping to meet the cost of that.
Mr Cameron said: "I wanted to come because I care passionately about the future of our United Kingdom.
"I want us to vote to stay together on September 18 and I wanted to come to this, the most far-flung part of our United Kingdom, to listen to people, to hear their concerns and to give the message that I hope we stay together."
Scottish Energy Minister Fergus Ewing said: "It seems that even the prospect of Scottish independence is already getting action for Shetland from the UK Government and the first visit by a sitting Prime Minister for decades. Locals will no doubt ask - given Westminster's control over energy policy - why this move did not happen years ago.
"However there is a glaring omission from the Prime Minister's announcement. The Shetland Islands will be enabled to play their full part in Scotland's clean energy revolution only when they are connected to the mainland electricity grid.
"Shetland is the only community of its size in the entire British Isles which lacks such a connection. It is deeply disappointing the Prime Minister did not take this opportunity to rectify this anomaly.
"In July 2013, the First Minister set out the Lerwick Declaration - the essence of which is self-determination, support for subsidiarity and local decision making. This was followed in June this year with a commitment from the Scottish Government to explore with the Islands Councils how they can help steer our approach to energy under independence.
"Scotland is the most energy-rich nation in the European Union and Highlands and Islands in particular possess massive potential to generate cost-effective clean power. It must be right that the communities in those areas feel the benefit of the energy resources on their doorsteps.
"The question of how we build on our abundant energy resources is central to Scotland's constitutional debate. Independence would give responsibility for Scotland's natural resources to the people who are most likely to harness them wisely - those who live and work in Scotland."