A group of Somali pirates and private security forces exchanged gunfire as the pirates attempted to hijack a cargo ship.

The video shows a speedboat coming towards the ship as a private security contractor with a sub-machine gun takes aim at the incoming boat.

One guard is seen in the video firing warning shots around the incoming speedboat, landing just feet away.

“Where they at, what’s their position?” one contractor shouts, after the security guards finish up firing dozens of rounds at the speedboat.

As the first speedboat retreats, a second boat races toward the starboard of the ship.

“Second skip coming in,” security radios in.

The clip has been viewed more than seven million times.

In March, pirates hijacked an oil tanker off the coast of Somalia in what was the first hijacking of a large commercial ship since 2012, the Daily Mail reported.