Local civic dignitaries, including the mayor and council leader, were onboard HMS Astute, which is visiting Southampton, Hampshire, at the time of the incident.
The British Ministry of Defence said the shooting was not terrorist-related and there was no threat to the wider public.
An MoD spokesman said: “Two Royal Navy personnel have been involved in a firearms incident at Southampton docks where HMS Astute is alongside.
“Sadly, one has now died as a result of his injuries.
“A third Royal Navy serviceman has been arrested by Hampshire Constabulary and is now in custody.
“We are co-operating fully with the police investigation and a Royal Navy service investigation will begin in due course.”
Defence Secretary Dr Liam Fox said: “I am greatly saddened to hear of this tragic incident and of the death of a Royal Navy serviceman.”
It is understood that the two victims were male officers and the shooting was carried out with an SA80 service rifle.
It is also understood the gunman was on sentry duty and the shooting happened during a weapons changeover between shifts.
After the shooting, it is understood the gunman was grabbed by other navy personnel who handed him over to Ministry of Defence Police.