This story has been updated throughout.

Francisco Erwin Galicia, the Dallas-born U.S. citizen who spent three weeks in the custody of U.S. Customs and Border Protection and Immigration and Customs Enforcement, was released Tuesday afternoon.

Galicia's case garnered national attention. The Dallas Morning News first reported on Monday that the 18-year-old had been held in CBP and ICE custody since June 27.

Sanjuana Galicia, Francisco’s mother, said Tuesday an ICE official called her around 2 p.m. and told her that they had found his documents and citizenship to be valid and that he had been freed.

"The first thing he said to me was, 'Mommy, they let me go. I'm free,' " she said by phone.

Galicia's detention appears to have been a bureaucratic mix up related to the fact that he had a U.S. birth certificate and also, years earlier, a Mexican visitor's visa to travel to the U.S. from Mexico.

Neither ICE nor CBP have responded to repeated requests for comment.

Francisco Galicia was born in Dallas in December 2000 at Parkland Memorial Hospital, according to a copy of his birth certificate provided to The News by his attorney, Claudia Galan.

When he was about a year old, his mother moved back to Mexico, pregnant with his younger brother, Marlon Galicia, who was born there.

Sanjuana Galicia said she then decided that she needed to escape the violence around her in Reynosa, a border city that Mexican drug cartels fight over to control drug smuggling routes into the U.S.

But she feared she might not be able to travel legally across the border with her sons.

The problem was that she wasn’t listed as Francisco’s mother on his birth certificate because she was using a fake ID when she was living and working in Dallas. Parkland staff used the name on that ID on the birth certificate.

Because she feared that would complicate her ability to get him a U.S. passport, she decided to solicit a visitor visa for Francisco by falsely claiming that he was born in Mexico.

Back in Texas, the family settled in Edinburg, where the boys eventually attended J. Economedes High School.

When Francisco Galicia and his brother set out on June 27, they were headed for a soccer scouting event at Ranger College in North Texas.

Robert Arce, assistant soccer coach at the high school, said Francisco is good enough to get a full-ride scholarship, showing speed, having height and exhibiting good sportsmanship.

“He’s a good kid, and he could go play anywhere,” Arce said.

But the boys had to pass through a CBP checkpoint in Falfurrias. It was there that the brothers were detained.

Francisco Erwin Galicia, a U.S. citizen who was born in Dallas, was released from immigration custody after wrongfully being detained for more than three weeks. Galicia lives in Edinburg and was traveling with a group of friends when they were stopped at a Border Patrol checkpoint. According to Galan, agents apprehended Galicia on suspicion that he was in the U.S. illegally even though he had a Texas state ID. (Sanjuana Galicia)

Francisco Galicia had a Texas ID, Social Security card and his birth certificate. Marlon had only a school ID and lacked legal status.

"We were confident that we'd be able to pass. We were going to do something good for our futures," Marlon told The News on Tuesday. "I didn't imagine this could happen and now I'm so sad that I'm not with my family."

Dallas immigration attorney Eric Cedillo, who is not involved in the case, said the complicated situation is a clear result of a mixed status family being at the mercy of the 100-mile border stretch where CBP has strong discretion at its disposal if it suspects someone of being in the country illegally.

“If they think you’re in the country illegally, then they might treat you like you don’t have rights. It’s their job to stop people who they think might be committing fraud against the U.S.,” Cedillo said.

Marlon was deported two days after he was detained. He is now in Reynosa with his grandmother.

Francisco Galicia’s fingerprints were scanned by CBP officers and they found his old visitor's visa listed in the system, causing CBP officers to doubt the validity of his Texas ID, birth certificate and Social Security card, said Galan, his attorney.

He languished in federal custody for about two weeks until the attorney hired by his mother presented his birth certificate, his health insurance card, a school ID and a congratulatory certificate Parkland staff gave to his mother the day he was born to CBP officers.

But they still didn’t release him.

Francisco Galicia, 18, with attorney Claudia Galan, was release from the South Texas Detention Facility in Pearsall on Tuesday. (Kin Man Hui / San Antonio Express-News)

Sarah Pierce, policy analyst at the Migration Policy Institute, said she’s never heard of a case like this one. But one thing is clear to her, she said: If Francisco’s documentation proved his citizenship then he should have been released as soon as possible.

“If he’s a citizen, then the Department of Homeland Security, it seems, really doesn’t have grounds to hold him,” Pierce said.

After Galicia’s story went public at major news sites beginning Monday evening, Galan planned to again meet with ICE officials on Tuesday afternoon. When she arrived, he had already been freed.

This isn’t the first case of a U.S. citizen being detained by immigration officers and being put in danger of deportation, Pierce said.

“But this speaks to how easy it is to fall into and escape ICE’s removal apparatus,” Pierce said.

A Los Angeles Times report from 2017 found that between 2002-17, at least 2,840 U.S. citizens were listed as being eligible for deportation.

Sanjuana Galicia herself could not travel from the family’s home in Edinburg to Pearsall, where her son was being held at the South Texas Detention Facility, because she lacks legal status and would have risked detention when passing through a CBP checkpoint.

“Thanks to God he has been released. My other son is still not with me. That still hurts, but thank God that Francisco has been released,” Sanjuana Galicia said.