When the agent approached the group, one person came forward and identified himself as a New York Police Department inspector, according to the person who reviewed the letter.

The letter says that the agent told the group to stay where they were until a supervisor could come — but the group ignored him and left, returning to the Mexican side. They later returned to the United States through the official checkpoints.

The letter appeared to be an attempt to memorialize that these events happened, the person said, and that the actions are violations that carry civil penalties or be subject to criminal prosecution. But the letter does not indicate that federal officials intended to take further steps.

In addressing the contretemps on Wednesday, during an appearance at a public housing complex in Brooklyn, the mayor denied having disobeyed an order from a border agent but did not deny or even address the central accusation of federal officials — that he had strayed across the border illegally.

Mr. de Blasio said that after he was turned away from the detention center, his security detail spoke with the border patrol about traveling into Mexico.

“The border agents consulted with their supervisor and they agreed, and they let our cars cross the American border into Mexico at a normal checkpoint,” Mr. de Blasio said. “While we were there, we were told where the border line was and we respected it.”

He added: “At no point did we disregard any instructions from federal authorities, period.”

Mr. de Blasio suggested that the Trump administration had leaked the letter to take attention away from the issue of family separation and cast it as an effort to intimidate him.