WASHINGTON — New York City Mayor Bill de Blasio and his security detail violated both Mexican and US immigration laws by crossing the border on foot during a visit near El Paso, Texas, US Customs and Border Protection alleges in a letter obtained by the Associated Press.

The mayor’s office flatly denied the allegation.

De Blasio, a fierce critic of the Trump administration’s immigration policies, went to the Texas border with about 20 other mayors from around the country on June 21, the day after President Donald Trump signed an order stopping family separations at the border.

More than 2,300 families were separated as a result of the administration’s “zero tolerance” policy, which criminally prosecutes anyone caught crossing illegally. The mayors said Trump had failed to address a humanitarian crisis of his own making.

De Blasio went to a holding facility for immigrant children but was denied entry. He then went to Mexico and crossed into the US to get a view of the facility. The New York Police Department runs de Blasio’s security detail.

According to the letter, a uniformed Border Patrol agent noticed a group on the Rio Grande River flood plain south of the Tornillo, Texas, Port of Entry, taking photos of the holding facility. The agent asked if anyone from Border Patrol or public affairs was there to authorize their presence. A New York Police Department inspector said no, according to the letter, and when the agent asked the group how they arrived, they pointed to Mexico.

The agent told them they’d crossed the border illegally and asked them to remain there while he got a supervisor and took them to an official crossing for an inspection per federal law, according to the letter. But the group disregarded the order and drove back to Mexico, according to the letter.

De Blasio spokesman Eric Phillips said the group did nothing illegal and had approval to be there.

“The mayor crossed the border with the direct approval and under the supervision of the border patrol supervisor at this port of entry,” Phillips said in an email Tuesday night to the AP. “Any suggestion otherwise is a flat-out lie and an obvious attempt by someone to attack the Mayor because of his advocacy for families being ripped apart at the border by the Trump Administration.”

A spokesman for the Border Protection had no comment.

The letter was sent June 25 by Aaron Hull, the chief patrol agent for the Border Patrol’s El Paso Sector, to New York Police Commissioner James O’Neill.