MANILA — The Philippines’ highest court ordered the government on Tuesday to release documents relating to thousands of deaths linked to President Rodrigo Duterte’s drug war.

Rights groups quickly welcomed the Supreme Court ruling, saying it would give closure to many families of the more than 20,000 people they estimate have been killed in the crackdown that Mr. Duterte has justified as necessary to end the drug trade.

A court spokesman said the solicitor general had been ordered to submit police and other reports on the killings to the Supreme Court within 60 days and to copy the petitioners.

The solicitor general, Jose Calida, had argued that sharing the documents with third parties could jeopardize national security. The court had previously rejected the same argument after the petition was filed last February, when Mr. Calida sought to avoid submitting the documents at all.