The Absalon was patrolling the Gulf of Aden under Nato command, reports say.
The Danish ship fired at the pirate ship to force it to stop, the Danish navy said on its website.
There were 17 pirates and 18 hostages on board the pirate ship, said its statement. Two hostages were found wounded and "could not be saved".
Absalon had for several days been watching a pirate mothership off the Somali coast, the statement said.
"Overnight Sunday to Monday, when the pirates tried to leave the coast, Absalon intervened and stopped the mothership, before it could pose a threat to shipping in the open sea," it added.
It fired at the mothership and its crew was then able to take control of the pirate ship.
Two of the hostages were found badly injured, and the Absalon doctor was unable to save them, the statement said.
The Danish warship is part of a Nato-led counter-piracy mission off Somalia and the east coast of Africa.
Nato said the incident was being investigated.