NEW YORK — A 17-year-old from El Salvador held for seven months after he was accused of gang activity on Long Island has been released after a federal lawsuit was filed on his behalf.

The teen is identified only as LVM in the court documents. He came to the U.S. with his mother after he was targeted by gangs in his country. According to the lawsuit he was arrested by immigration agents after officials said he flashed gang signs.

He was sent to a facility by the Office of Refugee Resettlement, which handles children. At a custody hearing in December, a judge rejected the gang allegations.

But he wasn’t released until shortly after the lawsuit was filed on Feb. 16. The suit seeks to represent others in similar situations.