SAN JOSE — A Santa Clara sergeant accused of masturbating nude in front of a Santana Row salesclerk when he was off duty last year testified Thursday that the woman had merely walked in on him while he was urinating in the boutique’s bathroom.

Yet Sgt. Thomas Leipelt did not deny the woman’s accusation at the time. Instead, he just said he was sorry it happened and departed from Annieglass, which sells jewelry and handmade glass housewares.

On Thursday, he testified under repeated questioning by prosecutor Lindsay Walsh that he didn’t proclaim his innocence because he wanted to be “respectful.”

“I used her bathroom and made an uncomfortable situation,” Leipelt said in response to Walsh’s skeptical questions.

Leipelt, 46, is being tried on one misdemeanor count of indecent exposure in a case that also relies heavily on the woman’s credibility, which has also come under attack. The veteran officer with 24 years experience has been on paid administrative leave since his arrest in July, about six weeks after the May 15, 2015, encounter. If he is convicted, he would face up to a year in county jail, have to register as a sex offender for life and most likely lose his job.

Earlier this week, the woman, who this newspaper is identifying as Jane Doe to protect her identity, told the jury of six men and six women that this was the first incident of its kind she has ever experienced.

But Leipelt’s lawyer, Cameron Bowman, produced evidence that she had actually filed a restraining order in 2009 against a former tenant who allegedly exposed himself in her home.

When questioned about why she didn’t divulge the previous incident earlier, Doe said several times, “I’m perimenopausal.” She also said it slipped her mind because it was her friends, not her, who were the victims. Bowman seized on that statement and noted that Doe had filed a restraining order after the previous incident, claiming under penalty of perjury that she had been a victim.

Both sides agree that the incident began when Leipelt showed up to visit his girlfriend Crystal Hardin, the other salesclerk at the store. They were having a secret extramarital affair, he said. The couple headed to the back storage room and began kissing and engaging in heavy petting, then decided to have sex in the adjacent employees’ bathroom.

A couple of Hardin’s friends showed up asking for her. That’s where the two accounts begin to diverge.

Doe came back to the storage room to tell Hardin, whom she said emerged in a disheveled state. Doe said she caught a glimpse of Leipelt in her peripheral vision and that nothing seemed amiss.

But a few minutes later, Doe returned to the storage room to retrieve a document from a printer, only to meet with the sight of a fully naked Leipelt facing her, sitting in a chair while masturbating.

“He was nude. He had no clothes on,” Doe testified. “Not even a sock.” They briefly made eye contact, and Leipelt looked at her and said, “Come here,” Doe testified. She said “No” and immediately left.

After a harried few moments, Hardin returned to the storage room and told Leipelt what Doe said had happened, and both she and Leipelt apologized.

Doe testified that the sergeant said, “I guess I went a little too far.” Hardin was fired from her job at the store a few days later.

But Leipelt gives a completely different account of which part of the store he was in when Doe walked in and what he was doing.

He denied he was ever nude, testifying that he only pulled his pants and underwear down while having sex. Just as he was having second thoughts about continuing to have sex in the bathroom, Doe knocked on the door. The sergeant said he had been feeling guilty about the affair — which had been going on irregularly for about a year, according to Hardin.

He and Hardin came out of the bathroom fully clothed, he said. Hardin then told him to wait a few minutes while she visited with her friends. He said he used the time to order pizza and call his family. Then he returned to the bathroom and was urinating with the door closed when it opened. He said he heard Doe gasp and say something like, “Oh, my.”

Asked by his lawyer what he thought when Hardin told him what Doe claimed he did, the sergeant testified he was “shocked.”

Contact Tracey Kaplan at 408-278-3482. Follow her at Twitter.com/tkaplanreport.