Montgomery County Circuit Courthouse, where Friday’s hearing for Jose Montano was held. (Dan Morse)

Jose Montano, a 17-year-old youth in Maryland accused and then cleared of sex assault charges in a high-profile case over allegations of a brutal rape in a high school bathroom, admitted to a far less serious offense Friday of having a lewd video of a juvenile in his phone.

The resolution of the state criminal case — in Montgomery County Juvenile Court — clears the way for another battle: whether Montano, a native of El Salvador who entered the country illegally last year, will be granted residency status or deported.

“There’s a lot of work to be done,” said one of his attorneys, Jose Canto, “but I think he has a chance to get a green card.”

The plea represented a quiet resolution to a story that attracted national attention and mention in a White House press briefing as it became part of the larger debate over illegal immigration.

Montano pleaded “involvement,” a juvenile court term, to possessing a pornographic video of the girl at the center of the rape case. She made the video, which was about 10 seconds long, and sent it to Montano the night before the purported rape, according to Montano’s attorneys.

Montano’s immediate future is not clear. He is being held at a juvenile detention center in Virginia. A Montgomery judge on Friday scheduled a hearing for Aug. 16, and he may ultimately release Montano to his relatives.

The original case surfaced in mid-March, after Montgomery County detectives were called to Rockville High School. They met the 14-year-old student, who told them that Montano and his friend, 18-year-old Henry Sanchez Milian, had repeatedly raped her in a bathroom stall.

The detectives questioned Sanchez Milian, who acknowledged he and Montano had sex with the girl. Detectives questioned Montano, who said they’d gone into the bathroom merely to tell jokes, according to a police affidavit. Detectives charged both teens with two counts of first-degree sex offense and one count of first-degree rape. Montano, a juvenile, was charged as an adult.

News accounts revealed the teens’ immigration histories. Sanchez Milian also had entered the country illegally a year earlier, from Guatemala. Both teens had been detained at the border then allowed to continue on to Montgomery County, where they enrolled at Rockville High as ninth-graders while awaiting possible immigration court proceedings.

In the rape case, defense lawyers for the two asserted the sex acts in the bathroom were consensual.

Prosecutors at the Montgomery County State’s Attorney’s Office reviewed the case and eventually determined there were too many inconsistencies and the facts didn’t support the original charges. In May, they dropped all sex assault charges against the teens.

But as they did, prosecutors then filed child pornography charges against Montano and Sanchez Milian over two images — a video and a photo — on the teens’ phones of the girl. The images, according to the teens’ attorneys, had been sent by the girl to Montano, who shared them with Sanchez Milian.

Prosecutors pursued the new case against Sanchez Milian in adult court, charging him with two counts of possession of child pornography. That case is pending, a trial date set for Oct. 30. Sanchez Milian remains held in the Montgomery jail, where immigration agents have lodged a detainer against him — an indication they could eventually move to to try to have him deported.

The new case against Montano went into juvenile court, where he was charged with two counts of possession of child pornography and two counts of distribution of child pornography because he sent the images to Sanchez Milian.

Juvenile court proceedings, including charges, often are kept confidential, and The Washington Post generally does not identify juvenile defendants who are not charged as adults. But Montano’s attorneys had wanted the hearings open and did not object to a reporter being present.

Attorneys for the two teenagers have long said the pornography charges were too harsh and amounted to a stretch of child pornography laws designed to go after adults. The attorneys also noted that the images being used against their clients had been part of communications that had helped lead to the rape case being dropped.

At a half-hour hearing Friday, Assistant State’s Attorney Mary Herdman told Circuit Judge Cynthia Callahan the parties had reached a resolution, and she would no longer be pursuing a recent effort to move the pornography case against Montano to adult court.

Under his plea, Montano pleaded involvement to one of the child pornography possession counts, and prosecutors dropped the other possession count and the two distribution counts.

Montano, wearing a blue polo shirt and listening over a headset to a Spanish interpreter, answered questions designed to establish he wanted to accept the plea deal.

Herdman read a brief summary of what prosecutors would have presented had the case gone to trial andsaid police found the images on Montano’s Instagram account.

Outside of court, David Wooten, an attorney for Montano, said his client has learned he “needs to respect girls more” and that consensual sex in a high school bathroom is bad behavior. “He understands that was a horrible decision,” Wooten said.

He said given Montano’s background in El Salvador — he was abandoned by his parents, he fled the country to get away from gangs trying to recruit him, his attorneys said — he has a case to make for being allowed to stay in the United States.