A Danish naval patrol killed four pirates in an exchange of fire in the Gulf of Guinea off the coast of Nigeria, Denmark's armed forces said on Thursday.
"No Danish soldiers were injured, but five pirates were shot," the military said.
"Four of the pirates died. One was injured," it added.
The incident occurred on Wednesday when the frigate Esbern Snare, which has been patrolling the area since early November, attempted to board the pirate boat.
The Danish forces fired warning shots, and the pirates immediately fired back.
"The Danish soldiers acted in self-defence and returned fire," the statement said.
Danish Prime Minister Mette Frederiksen told a news conference that the soldiers' intervention had "probably prevented concrete pirate attacks against vessels in the region."
Frederiksen, who had been scheduled to visit the Danish ship later Thursday during a visit to Ghana, said the Esbern Snare had "made an important and significant contribution to security in the Gulf of Guinea.
The head of the federation of Danish shipowners, Anne Steffensen, praised the intervention.
"The presence of Danish soldiers is absolutely necessary and, even if this appears harsh, piracy has a price," she said.
After the shooting, the pirate ship sank and the eight pirates were brought aboard the frigate, where a seriously injured one of their number was treated.
A piracy hotspot stretching 5,700 kilometres (3,540 miles) from Senegal to Angola, the Gulf of Guinea saw 195 attacks in 2020.
The same year, 130 of 135 hostage takings at sea occurred in the region, according to the International Maritime Office.
The Danish helicopter-equipped frigate and its 175 sailors "are fulfilling an important task by protecting Danish and other commercial vessels in the region," Defence Minister Trine Bramsen told news agency Ritzau.
Copenhagen in March announced it was sending the vessel to patrol the zone, where some 40 Danish ships operate daily.
Danish Prime Minister Mette Frederiksen is currently in neighbouring Ghana and due to visit the Esbern Snare.