A US Coast Guard crew have had a lucky escape after a dip in the Pacific almost went horribly wrong.

Footage from the cutter Kimball shared on the USCG's Facebook page shows about 40 carefree seafarers jumping into the sea and frolicking with an inflatable unicorn on Tuesday.

But those on board the vessel soon spotted a 2.4-metre shark, possible a mako or pelagic thresher, heading straight towards the group.

As warnings were shouted from the ship and the swimmers scrambled to make it back on board, petty officer Samuel Cintron fired live rounds into the sea to deter the potentially hungry visitor.

This tactic worked briefly, but the shark kept coming back, meaning more shots fired alarmingly close to Cintron's panicked colleagues.

All crew were eventually accounted for without injury — and even the unicorn was safely retrieved.

The shark is believed to have retreated unharmed.

"Everyone was having a great day. Everyone was smiling and having fun. It was perfect! And then ... bridge personnel reported 'Shark!' over the radio," the USCG posted.

Bizarrely, this is the second shipping incident involving an inflatable unicorn in a matter of days.

The 1,000-gt Greek ropax Salaminomachos (built 2008) hit the headlines on Monday when it rescued a four-year-old girl whose inflatable had drifted out to sea off the port of Antirrio.