When a cautious but enlightened Admiralty experimented by taking 12 talented young men from the lower deck (at a time when there was hardly any way for a rating to become an officer), Palmer was one of those sent to the Royal Navy College, Greenwich, for a year's training. There he was commissioned as an acting sub-lieutenant in 1937.
His first ship as an officer was the sloop Deptford, on anti-slavery patrols in the Red Sea and Persian Gulf; but on outbreak of war Deptford was redeployed to Atlantic convoy duties. On December 21/22 1941 she was north east of the Azores escorting convoy HG76 from Gibraltar to Liverpool when, in a "wild night-time action", the escort carrier Audacity and a U-boat were sunk. Deptford carried out five attacks on the submerged boat, which was shown after the war to have been U-567, commanded by the ace Engelbert Endrass.
Later that day a tired Palmer was officer of the watch when in fog he mistook the sloop Stork, commanded by the escort commander Johnny Walker, for a surfaced U-boat and rammed her. Walker treated this as the fog of war, and Palmer was awarded a DSC.
After Belfast Palmer was appointed to the minesweeper Catherine, which helped to sweep the Skagerrak, one of the most easily mined areas in the seas of northern Europe. On May 9 Catherine led the 40th Minesweeping Flotilla into Copenhagen, where the German cruisers Prinz Eugen and Nurnberg surrendered.
Palmer's expertise in explosives and countermining led to his involvement in the "British Bang" when, on April 18 1947, the Royal Navy blew up 6,800 tons of unstable ordnance on the island of Heligoland, in what is believed to have been the largest man-made, non-nuclear detonation in history.
The data from the shock, measured by ships positioned across the North Sea, formed the first seismic survey from which the existence of the oil and gas fields was surmised.
Later that year Palmer joined the destroyer Chequers, whose first lieutenant was the Duke of Edinburgh. Palmer taught at the submarine school, HMS Dolphin, and helped to develop high-frequency mine-hunting sonar at Portland.
His last appointment, in the mid-1960s, was Commodore Superintendent of the dockyard in Malta and Queen's Harbourmaster, based in the fort HMS St Angelo that overlooks Grand Harbour.
In retirement Palmer became a principal secretary in the newly created Ministry of Power, under Anthony Wedgwood Benn. But feeling underused and constrained by civil service procedures and disparaging the lack of analysis and strategy of the minister's close associates, he resigned after a year.
Instead he became harbourmaster at Penzance, where he opposed the infilling of the drying harbour to make a car park and deplored the lack of local investment. In the summer he liked to slip away in a small yacht to the French coast in order to study the differences between English town councils and French communes, and then urge Breton-style harbour development in England. At Mousehole, Palmer criticised new planning applications, especially those concerning roads, new homes and alterations to houses. But when persuaded to stand for election as a councillor, he found himself ill-suited to the compromises of parish politics and soon resigned.
Palmer served for many years on health committees in Cornwall, where he took a particular interest in mental health care, and was an active member of the league of friends of West Cornwall Hospital.
He made pottery in the style of Bernard Leach and the St Ives School and experimented with a variety of Chinese glazes at home. In his terraced garden he liked plants to stand up straight, and gradually turned from rows of vegetables to camellias, lilies and irises.
Whenever possible Palmer attended Sunday matins, but he was not a passive listener to sermons and occasionally led his family out in protest. His wife attended Holy Communion so that there could be no family dispute about what the preacher had said or meant.
Palmer left few written records but his diary of Belfast's bombardment at the Normandy landings in 1944, written on echo-sounder paper, has been donated to the Imperial War Museum.
Andy Palmer, who died on June 5, married Marian "Bina" Marsden in 1941, who died in 2001; he is survived by their two sons and two daughters.