The Danish military says the frigate Esborn Snare spotted the suspected pirate ship near several commercial ships.
Danish armed forces say a Danish naval patrol killed four pirates in an exchange of fire in the Gulf of Guinea off the coast of Nigeria.
“No Danish soldiers were injured, but five pirates were shot,” the military said on Thursday.
“Four pirates were killed. One got injured,” it added.
A spokesman said the incident took place outside Nigeria’s waters.
The incident happened on Wednesday when the frigate Esborn Snare, which had been patrolling the area since early November, attempted to board a pirate boat.
Danish forces fired warning shells and the pirates immediately retaliated.
“Danish troops acted in self-defense and retaliated,” the statement said.
The spokesman said the warship fired for the first time during the ongoing mission in the Gulf of Guinea.
The military said the remaining four pirates were taken to the battleship. After the shooting, the pirate ship sank.
A piracy hotspot stretching 5,700 km (3,540 mi) from Senegal to Angola, the Gulf of Guinea, saw 195 attacks in 2020.
That same year, according to the International Maritime Office, 130 of the 135 hostages at sea occurred in the area.
The Danish helicopter-equipped frigate and its 175 sailors “are fulfilling an important task by protecting Danish and other commercial vessels in the region”, Defense Minister Trine Bramsen told news agency Ritzau.
Copenhagen announced in March that it was sending the ship to patrol an area where about 40 Danish ships operate daily.
Danish Prime Minister Mette Fredriksen and main opposition MP Jakob Allemann had both planned to visit the warship during their visit to Ghana on Wednesday and Thursday.
Danish tabloid Ekstra Bladet reported on Thursday that they were not on the frigate when the incident took place.
The warship will operate in the Gulf till April next year.