The Diet enacted a bill Wednesday that allows security guards to carry rifles aboard Japan-registered vessels to counter piracy off Somalia and elsewhere.

The legislation, passed with support from both the ruling and opposition camps, is the first in Japan to authorize private citizens to carry and use firearms.

The new law allows armed guards employed by foreign security contractors to fire warning shots to keep pirates from approaching a vessel.

The legislation applies only to tankers and other Japanese-flagged vessels that sail in piracy-prone waters, including the Gulf of Aden off Somalia, the Arabian Sea and the Red Sea.

The law allows guards to fire on pirates only in an emergency where the lives of the guards or other crew members are at risk.

Whenever vessels call at Japanese ports, the Japan Coast Guard will inspect them to ensure no rifles remain on board. Unless this is confirmed, crew and freight will not be allowed off the ship.

Ship owners will be required to draw up a security plan for each vessel that stipulates measures to counter pirate attacks and how to store rifles on board.

Operators of Japan-registered ships are obliged to report the names of security guards and the length of their stay on board.