Updated

A Mexican federal judge sent Andrew Tahmooressi back to prison after the U.S. Marine sergeant made his first official courtroom appearance since being locked up more than three months ago for accidentally crossing the border with guns in his pickup truck.

The 26-year-old veteran of two tours in Afghanistan was finally able to tell his story to a judge, after his case had been delayed by both Mexico's unpredictable legal system and his own trouble settling on a lawyer. It was not immediately clear what Tahmooressi said at the evidentiary hearing, which was closed to the public. The next hearing in the case is scheduled for August 4.

Despite the judge's ruling, Tahmooressi's attorney, Fernando Benitez, told reporters that he was confident that the Marine's case was on the right track. Benitez said that his client's statement to the judge was "sound and made perfect sense," and claimed that irregularities with Tahmooressi's detention were grounds for dismissal of the case. The attorney said that his client was not provided with consular services for nearly eight hours after he was detained, nor did he have access to an adequate translator.

In addition, Benitez said that the order to search Tahmooressi's vehicle was dated March 28, three days before the Marine crossed the border.

Benitez had earlier sought to dampen hopes that federal Judge Victor Octavio Luna Escobedo would free Tahmooressi, although supporters, including his mother, Jill Tahmooressi, had held out hope.

More On This...

    Tahmooressi has been held since March 31, when he accidentally drove into Mexico at the San Ysidro, Calif., Port of Entry late March 31, after becoming disoriented from poorly lit street signs and being in a position on the road unable to make a last ditch U-turn. His family believes his post-traumatic stress disorder also may have contributed to his confusion. He was charged with violating Mexico's strict gun laws because he had three registered guns, along with all his worldly possessions, in his vehicle.

    Tahmooressi  appeared in court on April 28, but that hearing was gaveled before it began after the judge learned Tahmooressi had his attorney fired the night before for advising Tahmooressi to commit what the family considered to be perjury.

    After Wednesday’s hearing, Tahmooressi was taken back to El Hongo Prison in Tecate under heavily-armed guard.

    Bringing weapons into Mexico is a violation of the country's federal law. Complicating Tahmooressi's plight at the time of his arrest was that he had military-grade weapons and ammunition, as defined by Mexican statute.

    He was in the San Diego area for treatment of combat-related PTSD, having recently moved from Florida, and had all of his possessions, including the legally-purchased weapons, in his vehicle when he was stopped at the border.

    Tahmooressi served two tours of duty in Afghanistan, where he was involved in an IED attack that destroyed his vehicle. Because of his leadership and heroism in the field, Tahmooressi received a battlefield promotion to sergeant.

    Since his arrest, there have been dozens of appeals to the U.S. State Department and Mexican officials, led by Rep. Duncan Hunter, R-Calif., to secure Tahmooressi's release.

    On July 8, Hunter and Rep. Lee Terry, R-Neb., sent a letter to Escobedo, imploring him to take into consideration the circumstances surrounding his accidental entry into Mexico.

    "We believe the evidence supports Andrew's claim that he mistakenly entered into Mexico," wrote the congressmen. "One of the most compelling pieces of evidence is a 911 call Andrew made at the border checkpoint, where he stated he was unaware of his location."

    Joe Kasper, deputy chief of staff for Hunter, said the lawmakers wanted to show Tahmooressi has overwhelming support across the border, and that the case is being tracked very closely.

    "The letters will be used by the lawyers to show the deep support for Andrew and that quick resolution is important in the interest of the broader U.S.-Mexico relationship," Kasper said.

    The delays in his case were precipitated by multiple changes in his defense team. Since April 28, Tahmooressi has had three defense attorneys, including Benitez.

    "We're confident we finally have the right attorney for Andrew's case," Jill Tahmooressi said.

    Despite the apparent sincerity of Tahmooressi's mistake, there is a likelihood the case will run its course, according to Benitez.

    "This is a federal court and as in any democratic nation you will not find an executive calling up a judge and ordering the release of a suspect," Benitez told FoxNews.com after his hiring. "It makes no difference if it is a mayor, governor, or the president, there's not a phone call in the world that will change this."

    Upcoming hearings have not yet been announced, although the judge plans to visit the border checkpoint where Tahmooressi was nabbed. Benitez said he will be concentrating on the fact that Tahmooressi was held at the border by the Mexican military for some seven hours before being formally charged.

    A spokesman for the Mexican Embassy in Washington said that Tahmooressi was neither in a Marine uniform nor on official duty when he crossed into Mexico.

    "In Mexico, as in the United  States, ignorance of the law, error, or failure to understand the consequences of violating the law do not exempt individuals from responsibility, regardless of intention," said a factsheet on Tahmooressi's case provided by Ariel Moutsatsos Morales Basilio.

    He said in Mexico, unlike in the United States, there is no prosecutorial discretion, and that once a prosecutor has enough evidence to suggest that a crime was committed, he or she is obligated by law to prosecute.

    Fox News' Dan Gallo contributed to this report.