PALO ALTO — Sean Ryan thought everything was set: he’d struck a deal to serve a year in county jail for having sex with a 15-year-old girl who claimed she was an adult.

But when the victim showed up at Ryan’s sentencing hearing to ask that he be sent to state prison and required to register as a sex offender for life, the case took a surprising turn.

In a rare move, Santa Clara County Superior Court Judge Vincent J. Chiarello pulled the plug on the deal he had helped negotiate, which had included letting Ryan voluntarily go to jail three months before the agreement was to be finalized. In explaining his change of heart, the judge said he agreed with the victim that Ryan would be a danger to others unless he were imprisoned.

Defense lawyers claim Ryan was “Turner-ed,’’ a term they coined to define what happens when a judge throws the book at a defendant to avoid becoming the target of the outrage that has fueled a recall movement against Judge Aaron Persky. Last summer, Persky gave former Stanford athlete Brock Turner a relatively lenient jail sentence for sexual assault after the victim’s powerful statement about her assault went viral.

Chiarello declined to comment and, as a judge, cannot discuss pending cases. But Ryan’s lawyer and other defense attorneys at the Palo Alto courthouse noted that Chiarello’s decision came three days after recall advocates, in a well-publicized move, filed notice to put their campaign to oust Persky on the June ballot.

“Judge Chiarello gave a whole raft of reasons for busting Ryan’s plea deal, all of which I thought were absolute baloney,’’ said Philip Schnayerson, Ryan’s lawyer. “The reason for his decision is he noticed one of his fellow judges was being filed on for a recall three days earlier and he was terrified.’’

In contrast, the judge later that morning spared another man from prison in a sex case, noted public defender Gary Goodman. The difference? No victims showed up to speak at the sentencing of Rob Chapman. Chapman had admitted going on “missions” to look for young girls to rub up against and was convicted of felony charges for inappropriately touching three girls at a grocery store and a mall by grabbing their buttocks or stroking their hair.

Stanford law professor Michele Dauber, who is leading the movement to recall Persky, says there’s no evidence that the political campaign played any role in Chiarello’s decision to set aside Ryan’s plea agreement. She praised Chiarello for listening to the victim, something Persky’s critics said he failed to do. According to a transcript of the hearing, Chiarello cited several other factors in his decision, including that the defendant had communicated online in a sexual manner with other girls he knew were underage.

“I commend this victim for coming forward,’’ Dauber said. “I think Judge Persky’s defenders are really doing a terrible disservice to her by trying to use her bravery in making that victim-impact statement to try to score points in their effort to help Judge Persky.’’

Sentencing experts note that judges must consider a complex range of factors in sentencing and that no two cases present an identical set of factors.

Persky touched off an international furor last summer by sentencing Turner to six months in jail for sexually assaulting an unconscious, intoxicated woman. Under California law, Turner, who returned to Ohio after serving three months of his sentence, will have to register as a sex offender for the rest of his life.

Ever since, attorneys have speculated about whether the fallout from the Turner case and the rare recall campaign against a sitting judge would prompt harsher sentences in sexual assault cases and charges involving violence against women. But Chiarello’s two rulings on the same day in June are the only ones so far to spark public debate.

“We’re very concerned about the effect and are keeping a close eye out,” Goodman said.

In Ryan’s case, the then-29-year-old first encountered the 15-year-old victim on Omegle, a free online chatroom. According to a police report, she told him she was 20 but was still in high school because she’d been sexually assaulted and was struggling to deal with the trauma. The first two times they met in person, they had sex, according to court records. The third time, she told him she was 15 and Ryan left without touching her.

However, they continued to talk online, and Ryan told police he sent her a photograph of a 14-year-old girl in Illinois he was chatting with online, a move his lawyer claimed was a clumsy attempt to break up with her. Ryan’s laptop also contained sexual discussions with a 15-year-old girl, according to a police report.

Ryan initially faced three felony counts of lewd and lascivious acts with a minor, which would have required him to register as a sex offender if convicted. Under California law, Ryan’s belief about the victim’s age is not a defense. He also faced one count of possession of child pornography after police found three images and one video involving children ages 13 to 16.

After psychological tests by a defense expert concluded Ryan did not present a threat to public safety, the prosecution agreed — with Chiarello’s blessing — to reduce the charges to felony unlawful sexual intercourse, which doesn’t require sex registration, and have him serve a year in jail.

“It was an excellent disposition,’’ said Assistant District Attorney Terry Harman, who oversees the sex crimes team. She said she found the judge’s decisions in both cases “baffling.’’ In addition, Chiarello in June released Ryan, an Afghanistan war veteran, from jail, pending trial in his court later this year.

In a statement she read aloud in court, the victim in his case said she felt it was her responsibility to speak up so “this doesn’t happen to other girls.’’

“It’s terrifying to me that he’s going to be back out on the street in less … in less than a year now,’’ she said.

Meanwhile, Chapman will have to register as a sex offender for life after admitting he couldn’t control his impulse to stalk a total of four girls, ages 7, 9 and 14. Chapman was also convicted in San Mateo of possessing child pornography and sentenced to a year in jail to be served at the same time as his Santa Clara County case.

Although a probation report concluded that Chapman’s behavior was predatory, the officer recommended a year in jail rather than a prison term — if a court-appointed psychologist deemed him a low risk for re-offending, which subsequently occurred. The girls were clothed, and Chapman had completed a substance abuse treatment program and enrolled in therapy, the report noted. Chiarello agreed, rejecting the prosecutor’s request for at least three years in prison and opting for a year in county jail. He also sentenced Chapman to five years probation and a sex offender treatment program.

Dauber criticized Chapman’s sentence as “unduly lenient,” but said it’s not all Chiarello’s fault. She claimed Persky shares in the blame because he initially presided over the case and offered the plea agreement. However, Persky’s involvement would not have prevented Chiarello from sending Chapman to prison.