An American citizen who was formerly an Army contractor overseeing computer technology at a base in Honduras is challenging whether federal prosecutors in Houston can charge him with a crime over an alleged sexual relationship with a 13-year-old girl in the Central American country.

William McGrath, 54, wants a judge here to dismiss the indictment on the grounds the U.S. government does not have the authority to prosecute him for matters outside its borders, according to court documents.

McGrath allegedly met the girl in 2013 at a Honduran supermarket as she was buying her own cake for her 13th birthday, according to the FBI.

McGrath and the girl, who admits she at first deceived him about her age, allegedly went on to have an ongoing sexual relationship during which he gave her cash and gifts and took her out on dates to restaurants and hotels.

His lawyer, public defender Marjorie Meyers, said the allegations in a November indictment are outside the scope of U.S. law because they don’t relate to any criminal activity committed in the U.S.

“Prosecution of Mr. McGrath for sexual activity in Honduras is akin to prosecuting an American citizen who smokes hashish in Amsterdam, an activity that is legal in the Netherlands,” Meyers states in a motion filed last week in court.

“His sexual activity in Honduras has no relationship with commerce, much less foreign commerce, and may have been legal where it occurred,” she states.

Prosecutors have not yet formally responded to Meyers’ contentions. A judge has not ruled.

McGrath is charged with engaging in illicit sexual conduct in a foreign place with a minor, according to an indictment.

Houston-based FBI agents who focus on child exploitation and child sex tourism are probing the case.

McGrath told investigators that when he first met the girl, he thought she was 17, and he conceded that while he’d given her gifts and money, nothing was in exchange for having sex, according to an FBI affidavit that describes the investigation.

But the girl said she originally told McGrath she was 16, according to the affidavit, and afterward she revealed her real age but their relationship continued.

McGrath has expertise in Internet technology and was in charge of the Army’s computer systems at the Soto Cano Air Base in Honduras.

As part of the probe, agents reviewed Facebook conversations between McGrath and the girl.

“You’re too young to be with me in public,” McGrath allegedly wrote to her in August after she complained about him not spending enough time with her. “I’m not mad at you. I am upset about the rules and you are only 16 years old.”

In an October conversation with an adult who is not named in court documents, McGrath discussed the relationship in Honduras, noting that the girl was in love with him and that “it was an error on my part.”

An FBI agent testified in November that agents reviewed 18 hard drives taken from him and found he’d had online “contacts with a lot of young ladies” but that he was not aware any of them were a minor besides the girl in Honduras.

As for the girl in Honduras, he said she denied being involved in prostitution.

“In this young lady’s mind, she was having sex because she was attracted to Mr. McGrath,” the agent said. “She might have thought she was in love with him.”

The Army had no immediate comment status. A judge has ordered he remain in custody.