MEXICO CITY (Reuters) - Mexico's foreign ministry said on Thursday it is only holding a North Korean ship that ran aground in its waters last year in order to comply with United Nations rules.

The 6,700-tonne freighter Mu Du Bong, which had come from Cuba, hit a reef near Tuxpan in Mexico's eastern Veracruz state in July last year.

North Korea's Deputy U.N. Ambassador on Wednesday accused Mexico of illegally detaining the ship and crew, warning it would take "necessary measures" to release the vessel.

In a statement explaining why it had not yet released the vessel, Mexico's foreign ministry said authorities had originally fined the ship's owners for the environmental damage it caused. But before releasing the ship, the United Nations told Mexico there was evidence it belonged to blacklisted North Korean firm, Ocean Maritime Management Company.

The foreign ministry said a UN delegation had visited the ship to investigate, adding that under the UN Charter it could not release the ship until the investigation was over.

The foreign ministry also said the 33 crew members were enjoying "free transit" and had not been charged with anything, stressing that the detention of the ship was not motivated by differences between the two countries.

(Reporting by Christine Murray; Editing by Ken Wills)