Massachusetts is one of just two states without a law on the books officially criminalizing what’s often called revenge porn, but lawmakers took a major step Thursday toward shedding that designation.

The state Senate voted 40-0 to pass a bill that would amend the state's criminal harassment law and establish clear penalties, including fines and jail time, for sharing sexually explicit images or videos without the subject's consent. The bill also applies to "deepfake" photos or videos created through artificial intelligence, as well as original images.

Alex Hagerty watched the vote from the Senate gallery. The Abington resident has advocated for the bill over the past several months, testifying at a September hearing about his experience after a former partner posted a video of him online.

He said the vote sends a message "that Massachusetts stands with survivors and victims of revenge porn."

"Speaking as a survivor and getting to know so many survivors over my journey, and hearing some of the testimonies back in September, it's humbling to see now that finally that work is getting done to bring accountability for the survivors and victims and their families," Hagerty said.

The issue of revenge porn, also referred to as image-based sexual abuse, has been on lawmakers' radar since at least 2017, when then-Gov. Charlie Baker filed legislation to criminalize the practice.

But the House and Senate never got a final bill over the finish line in past years, despite sustained advocacy from Baker and revenge porn survivors.

This time around, the two chambers have each passed similar bills unanimously. They have more than four months of formal legislative sessions remaining to agree on specifics and send a final bill to Gov. Maura Healey.

Katelynn Spencer hopes to see a new law provide others with protection she couldn't find, and a chance to "actually get justice."

Spencer, a Fairhaven resident, discovered four years ago that an old friend of hers had posted two sexual videos of her online. One she remembered recording when she was 18, and she hadn't known the other existed. Both had been online for 10 years by the time she found out.

She said she brought the matter to police and to the courts, trying to get the perpetrator convicted of distribution of obscene material, but her case was ultimately dismissed.

Spencer said she wants lawmakers to understand the emotional, mental and physical toll victims face. She said her marriage ended, she lost friends and a career, and she experienced health issues.

"I feel like an object. I am an object to people. I'm not a person," she said. "I want to feel like a person in a situation, like, 'Hey, yeah, she might have agreed to make a video at 18, because, I don't know, we're all pretty stupid at 18.' And I loved him, and he begged me, and I gave in, but he also recorded me without me knowing.

"I still am a person, at the end of the day, that has a life, that has nephews, that had a career," Spencer continued.

As senators prepared to vote Thursday, they credited survivors who made the case for why the law change is necessary. Sen. John Keenan, the bill's lead sponsor, said the courage people have shown in sharing their stories has been "truly motivational."

Both the Senate legislation and a similar bill the House passed in January set new penalties for publishing or distributing sexual content "with the intent to harm, harass, intimidate, threaten, coerce or cause substantial emotional distress" and sharing such material "with reckless disregard for the depicted person’s lack of consent." Someone found guilty could face up to two and a half years in jail and a fine of up to $10,000, with a higher fine on a second offense.

The two bills overlap in other areas. Both address consensual teen sexting, calling for the creation of an educational diversion program for minors who share explicit images of themselves or peers without intending to cause harm. Lawmakers have said such a program would give law enforcement an alternative besides charging a young person with child pornography offenses that would require them to register as a sex offender.

Each bill would also add "coercive control" to the state's abuse laws. The change would allow someone to seek a restraining order against a family or household member for behavior meant to control, isolate or intimidate, including monitoring their communications, restricting their finances, threatening to publish explicit images, or hurting a pet.

The House and Senate will next need to agree on a final version of the bill, a negotiation that can sometimes be resolved quickly but can also stretch into months of closed-door talks.

Keenan, a Quincy Democrat, said lawmakers from the two chambers have worked closely together throughout the whole process.

"I think we share the same goal, which is to get this to the governor's desk, to give closure for people, and to send a message that we're not going to stand for this anymore here in the commonwealth," he said.