BOSTON — Gov. Deval Patrick on Thursday signed into law a bill restricting the shackling of female inmates while they’re pregnant or during childbirth.

“It blows my mind that I have to sign a law for that,” Patrick said after the bill-signing.

Rep. Kay Khan, D-Newton, who has repeatedly filed versions of the bill since 2001, said she had heard of a pregnant inmate shackled last week at Boston Medical Center.

“It’s been a long time coming,” she said of the bill.

Sen. Karen Spilka, D-Ashland, who pushed the bill in the Senate, called the practice “outrageous” and the legislation a “big step forward.”

“As a kid, I used to watch a lot of the old medieval movies, and literally that’s what I would picture in my mind, some of the old dungeons, when I’d hear about women being shackled,” she said.

Spilka and Khan, along with 10 other House and Senate legislators, joined Patrick for the bill signing, while advocates from the Massachusetts Anti-Shackling Coalition sat in the audience.

“Now the challenge is to ensure that it is implemented as intended so that no woman in labor is shackled at any time: not in the corrections facility, not during transport, and not in the hospital,” said Megan Amundson, executive director of NARAL Pro-Choice Massachusetts. “If this campaign did anything, I hope it opened the eyes of corrections officials so that they realize that shackling a pregnant woman puts her health and her pregnancy at risk. And that is unacceptable.”

The bill (S 2063) says a pregnant inmate, during the second or third trimester, or while recuperating after delivering a baby, can be transported to and from visits to medical providers and court proceedings in a vehicle with seatbelts and may only be restrained through handcuffs in front. An inmate in labor – “as determined by a licensed health care professional” – cannot be placed in restraints. Patrick signed 90-day emergency regulations in February as a stop-gap measure to restrict the practice. Nineteen other states also restrict the practice.