Costa Rica has issued an emergency alert after a ship carrying 180 tonnes of ammonium nitrate sank off the country's Pacific coast, releasing the massive amount of toxic cargo into the ocean.

The National Emergency Commission (CNE) urged people on Sunday to avoid swimming at beaches and suspend fishing in the region off the port of Puntarenas, 90 kilometres west of the capital.

The CNE said the accident occurred on Saturday when the boat, which was transporting ammonium nitrate for the fertiliser company Fertilizantes de Centroamerica, capsised in heavy seas. Two crew members were rescued without incident.

Ammonium nitrate is often used in the manufacture of fertilizers and explosives, and can be dangerous to health in cases of direct contact with the chemical.

The Tico Times, a Costa Rican news agency, said that "officials from several government agencies are scrambing to respond to the contamination".

Claudia Agraz Hernandez, an environmental expert, told the online news site ElPais.cr that the spill "could produce a proliferation of micro-algae, a depletion of oxygen in the waters, and the death of several marine species".

Other damages could include "problems with nutrients along the coast, water quality, and damage to the mangroves and fisheries, which could be significant," she said.

The CNE has also posted photos online showing floating dead fish that could have been killed by the spill.

Environmental groups urged authorities to fully investigate the accident and hold accountable those responsible for it, ElPais.cr reported.