Approval of the bill, which also would apply to male victims, came a day after the state’s highest court ruled that a man who took cellphone photos up the skirts of female passengers riding the Boston subway didn’t violate state law.

Top lawmakers said the bill will send a clear message to those who take so-called “upskirt” photos.

“It is sexual harassment. It’s an assault on another person whether it’s a child or an adult,” Senate President Therese Murray said moments after the Senate unanimously approved the bill. “Woman and children should be able to go to public places without feeling that they are not protected by the law.”

The legislation says anyone who “photographs, videotapes or electronically surveils” another person’s sexual or intimate parts without that person’s consent would face a misdemeanor charge and a maximum penalty of two-and-a-half years in jail and a $5,000 fine.

The crime becomes a felony with a maximum penalty of five years in prison and a $10,000 fine for photographs or recordings of a child under 18. Distributing such photos would carry a maximum punishment of 10 years in prison and a $10,000 fine. Murray said those who take such photos sometimes post them on pornographic websites.

House Speaker Robert DeLeo said the Legislature moved swiftly after the Supreme Judicial Court issued its ruling Wednesday.

“Not only did we get it done quickly, but I think there was a feeling that we did it right,” he said. “We wanted to make sure that this would be a law that would pass all legal questions that could arise.”

After additional procedural votes, the bill could reach Gov. Deval Patrick later Thursday or Friday. Patrick said he would sign the legislation.

DeLeo and Murray both expressed frustration with the court ruling, but said lawmakers are facing an ongoing challenge keeping up with rapidly changing technology.

“What we didn’t talk about yet are drones,” Murray said. “So now the drone issue will come up in the future also about privacy issues.”

Wednesday’s court decision overruled a lower court that had upheld charges against Michael Robertson, who was arrested in August 2010 by transit police who set up a sting after getting reports that he was using his cellphone to take photos and video up the skirts and dresses of female riders.

The state’s existing Peeping Tom law “does not apply to photographing (or videotaping or electronically surveilling) persons who are fully clothed and, in particular, does not reach the type of upskirting that the defendant is charged with,” the court said.

The SJC said that while such actions should be illegal, they are not, given the way state law is written.

In the past three years, MBTA police have investigated 13 “secretly photographing” cases. In some cases, the alleged offender was issued a court summons. Some remain open investigations. During those three years there was an average of 395 million passenger trips on the MBTA.