Hours before being whisked away in the middle of the night to a summer camp for troubled children, a teenage boy had sex with his best friends’ mother in a green SUV — while parked at a Los Gatos elementary school, the youth testified Wednesday.

The encounter at Daves Avenue Elementary School was the last of at least 30 to 40 times the middle-aged Los Gatos woman and 16-year-old boy had intercourse, the boy claimed in testimony that contradicted what he told police last year.

“Did you lie last year to detectives when you told them you only had sex with Sara Cole three or four times?” prosecutor Timothy S. Moore asked, as Cole’s trial on three felony counts of unlawful intercourse with a minor got under way Wednesday.

“Yes,” the youth instantly said in testimony that recounted a disturbing, drama-filled relationship with Cole. Now 17 and enrolled in a Montana boarding school — which has a curriculum that includes psychological counseling — the teen said he believed last year that telling the truth about the 3 ﻿1/2-month affair with the 47-year-old woman would “make me look bad and I wanted to save her (Cole).”

Cole made headlines — and benefited from an outpouring of community support — after a drunken driver nearly killed her in 2007.

Cole’s attorney, Michael W. Armstrong, pointed out inconsistencies Wednesday in the boy’s account, noting lies the teen told his parents and police, including not acknowledging his use of LSD and mushrooms. The boy also told detectives that Cole initiated the intercourse, but testified that “we looked at each other and it started to happen.” The Mercury News is not publishing the boy’s name because he is an alleged victim of sexual assault.

Cole has pleaded not guilty, insisting she only had “intimate relations,” not intercourse, with the boy. The mother of four sons is also charged with one misdemeanor count of molesting or annoying a child under 18. She may testify Thursday.

Judge Jerome E. Brock has excluded details of Cole’s accident on the grounds that they were irrelevant and could unduly evoke jurors’ sympathy.

During their relationship, which began 2﻿ 1/2 years after her accident, Cole and the teen exchanged 5,413 texts and 863 phone calls over seven months.

The teen’s parents first reported their suspicions to police after seeing a sexually graphic text message on their son’s phone. They discovered a series of disturbing texts after they had him taken to a wilderness camp for troubled children because he was getting poor grades and smoking marijuana.

Much to his surprise, the boy was jostled awake by camp counselors about 4 a.m. on July 15, 2010 — about eight hours after his alleged encounter with Cole in the elementary school parking lot — and flown to the Utah wilderness, where no cellphones or other electronic distractions were permitted.

The boy eventually reported the alleged sexual abuse to a therapist at the camp, who called his parents.

The boy, wearing a blue-plaid flannel shirt and jeans, told the rapt jury of seven women and five men that he and Cole often had sex in the kitchen or her bedroom while his best friend was in a nearby room sleeping or playing Xbox video games.

In the testimony, the boy described a relationship that was anything but desirable.

The teen said Cole supplied him with free food, cigarettes and marijuana — even driving him to pick up pot. Once, he said, she promised to wait for him outside his dealer’s house on Winchester Avenue, but left him stranded after discovering a text message on his cellphone from a girl he was dating, the youth testified.

The two appeared to battle constantly, judging from the text messages the prosecutor displayed for the jury. She once blocked his calls; he once damaged her back door after she locked him out because he stole her cigarettes, he testified.

Throughout the long afternoon, the boy remained poised, responding in a straightforward, mature manner even under gentle but persistent questioning by Armstrong.

But after stepping down from the witness box, he requested something of the judge that seemed to reflect his youth. Referring to a basket of treats clad in shiny gold paper that jurors had been passing around, the teen piped up, “Can I take a candy?” and grinned when the judge nodded his assent.

Contact Tracey Kaplan at 408-278-3482.