Spoiler alert: This post includes major plot points from Tuesday's episode of NCIS.

Abby Sciuto (Pauley Perrette), the pigtailed goth who's been the forensics whiz for 15 seasons on CBS's NCIS, left the agency she'd long served on her own terms Tuesday night, which was billed as Perrette's last appearance on the show.

For fans of the character-rich hit procedural, which stars Mark Harmon as Leroy Jethro Gibbs,  the leader of a team in the Naval Criminal Investigative Service, the fate of Abby wasn't the shocker many expected. Instead, it was revealed in the first few minutes that her colleague and dinner companion Clayton Reeves (Duane Henry) had been killed in the apparent mugging that left Abby clinging to life.

Apparent was the operative word. Abby's winning a fancy dinner for two in last week's episode? Not so random, it turned out, as we learned she'd been targeted by one of the many people she'd helped send to prison.

Abby, who woke up in the hospital less than halfway through the episode to learn the crushing news about Reeves, was the focus of a number of flashbacks, and viewers for the first time got to see her home, decorated with loving, lavish eccentricity for Perrette's final episode (complete with sleeping coffin).

"I'm tired of my hero friends dying," she announced in a showdown with  the man who tried to have her killed, whom she'd pretended to poison — and then coerced a confession out of with the "antidote." "Everyone has their breaking point. This was mine."

In the end, she planned to accompany Reeves' body to his native London, and to do the charity work he'd planned to.

Perrette, who with Harmon and David McCallum was one of the JAG spinoff's three remaining original characters, played a woman so openhearted that even with a gun pointed at her at the end of the May 1 episode, she was still offering to help the person holding it.

At least Perrette's fans can't say they weren't warned that something sad would happen, even if it wasn't the sad thing they'd been led to expect.

"I'm so worried about you guys for Tuesday's episode of the It's sad," Perrette, 49, wrote on Twitter on Monday, adding, "But I hope hope hope you will all watch."

Read more: Pauley Perrette announces she's leaving NCIS

In 15 seasons, Perrette left her mark on more than a TV show. Along with characters like 24's Chloe O'Brian (Mary Lynn Rajskub) and Bones' Dr. Temperance Brennan (Emily Deschanel), she made being a girl geek look cool and is credited with having inspired some female viewers to pursue careers in science and technology.

Pauley Perrette as Abby Sciuoto in a scene from the May 8 episode of CBS’s “NCIS,” which was Perrette’s final one for the series, after 15 seasons.
Patrick McElhenney/CBS
Pauley Perrette as Abby Sciuoto in a scene from the May 8 episode of CBS’s “NCIS,” which was Perrette’s final one for the series, after 15 seasons.

"It's called the Abby Effect," said Perrettte in a 2011 interview.

"These girls started watching when they were young, and they're in college now," Perrette said.

"I get letters and stuff from people all the time, all over the world — parents, grandparents, kids themselves — that say this fictional character that I play" influenced them, "and now they're pursuing math and science. … I went to college, I loved school. I love math and science myself. And to be able to play this character that has literally made young girls think that it's OK for them to pursue math and science is unbelievable," she said.

“Don said he thought alternative and artistic kids were only being portrayed in the media as junkies, thieves, and criminals, and he wanted to turn that on its head and show [one] who is brilliant, responsible, and capable and goes to church. It really worked,” Perrette says. “I think, after all these years, an older generation might look at someone with tattoos and instead of thinking they’re a thug, they maybe think they’re a scientist.”

NCIS, which concludes its 15th season on May 22, has already been renewed for a 16th.