Leading Seaman (Above Water Warfare) Kevin Moffat, 45, from Edinburgh, had denied unlawful possession of a firearm during his earlier court martial but was convicted by a panel.
Judge Advocate Robert Hill, sitting at Bulford Court Martial Centre in Wiltshire, imposed the term to be served at a civilian jail, an official confirmed.
Moffat was drafted at short notice to serve on the now-decommissioned HMS Edinburgh last summer.
He became worried as his partner was due to give birth this January.
On September 28 he took an SA80 service rifle and went to the cabin of Lieutenant Commander Robert Williams and said: "Sir, you know me, this is a loaded weapon and it's cocked. I want to talk to you."
He denied threatening Lt Cdr Williams and claimed he instead told him: "Sir, you know me, this is not a loaded weapon. I want to talk to you."