DUBLIN -- Lawmakers overwhelmingly voted Friday to back Ireland's first bill on abortion, legalizing the practice in exceptional cases where doctors deem the woman's life at risk from her pregnancy, as the predominantly Catholic country took its first legislative step away from an outright ban.

Exhausted legislators applauded Friday's 127-31 vote, while outside the parliament gates abortion rights activists cheered as they watched the result on their smartphones. It capped a grueling debate that locked lawmakers in argument from Wednesday morning to 5 a.m. Thursday and, after a pause for sleep, through midnight Friday.

While the decisive outcome was expected given Prime Minister Enda Kenny's lopsided parliamentary majority, passage of the Protection of Life During Pregnancy Bill did inflict damage on Kenny's 2-year-old coalition government.

Catholic conservatives vowed to drive his centrist Fine Gael party from power for violating its 2011 campaign pledge not to legislate on abortion. The government drafted the bill in response to last year's case of a miscarrying woman who died in an Irish hospital from blood poisoning nearly a week after being refused a termination. The death highlighted Ireland's failure for two decades to draft abortion legislation in support of a 1992 Supreme Court judgment ruling that life-saving abortions, including to prevent suicides, should be legal in Ireland.

Kenny, meanwhile, expelled five of his 74 lawmakers from Fine Gael's parliamentary group for voting against the bill and said they couldn't seek re-election as Fine Gael candidates. Strong support for the bill came from left-wing politicians, including Kenny's coalition partners in the Labour Party, who favor much easier access to abortion.

Many lawmakers in the round-the-clock debate expressed hopes, or fears, that passage of the bill would put Ireland on a slippery slope to granting wider abortion rights, as has already happened in the rest of Europe. The island of Malta is the only other European Union member to outlaw the practice.

Divisions ran deepest on the bill's provisions permitting an abortion for a suicidal woman if a three-doctor panel agrees she would try to kill herself if denied a termination. Anti-abortion activists warned that suicide-faking women and sympathetic doctors would exploit the rule.

But abortion rights lobbyists countered that such cases were rare, and even the most distressed abortion seekers would take the easier option of traveling to England, where abortion has been legal since 1967. Figures released Thursday showed that nearly 4,000 Irish women traveled there for abortions last year, while many hundreds more have performed their own at home using miscarriage-inducing pills ordered over the internet.

The epic debate reflected Kenny's determination to get the bill passed before parliament closes for summer holidays next week. The marathon took its mental toll on lawmakers, one of whom accidentally pressed the wrong button during a 5 a.m. vote to reject opposition amendments.

Another lawmaker, Tom Barry, grabbed a female colleague, Aine Collins, by the hips during a 3 a.m. amendment vote and pulled her on to his lap right in the middle of the debating chamber. Both are Fine Gael lawmakers from County Cork.

Barry said he'd just been kidding around after Collins noted how cold the debating chamber had become. Once the scene became a viral video in Ireland, he issued an apology describing his actions as "disrespectful and inappropriate. ... No excuses, I just shouldn't have done it." He later received an official reprimand from Fine Gael superiors.

Within minutes of debate resuming Thursday afternoon, the speaker was telling both sides to shut up because they were making his sleep-deprived head hurt.

"There's a lot of tired bodies in this chamber, including myself, and my tolerance level is getting less by the second listening to you lot, shouting and roaring across the chamber," Sean Barrett said in remarks to the entire 166-member parliament.

Outside the parliament building, rival abortion protesters maintained a round-the-clock vigil. Police kept them separated, except when one anti-abortion activist flicked Catholic holy water into the ranks of abortion rights protesters, Exorcist-style.

Both sides also shouted occasional insults at each other, though the anti-abortion protesters spent long periods on their knees with rosary beads in hand. At dusk, many lit votive candles. One accidentally set fire to a pro-life poster, but the flames were extinguished with more holy water.

Related on HuffPost:

Loading Slideshow...
  • A protester holds rosary beads with a anti-abortion placard in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 during a demonstration ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • Anti-abortion campaigners wait outside the Irish Parliament at Leinster House, Dublin ahead of a parliamentary vote on abortion. Wednesday July 10, 2013. (AP Photo/ Julien Behal/PA)

  • A Pro-Choice supporter holds placards in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • Lucinda Creagon holds an anti-abortion placard in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 during a demonstration ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • Pro-Choice supporters hold placards in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 during a demonstration ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • People walk pass anti-abortion placard in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 during a demonstration ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • A pro-abortion supporter holds up a placard in front of the gates of the Irish Parliament building in Dublin on July 10, 2013 during a demonstration ahead of a vote to introduce abortion in limited cases where the mother's life is at risk. (PETER MUHLY/AFP/Getty Images)

  • Anti-abortion protesters holding placards walk through Ireland's capital, Dublin, in an anti-abortion protest Saturday, July 6, 2013. (AP Photo/Shawn Pogatchnik)

  • Thousands of anti-abortion protesters fill Dublin's major thoroughfare, as they march against Ireland's abortion bill Saturday, July 6, 2013. (AP Photo/Shawn Pogatchnik)

  • In this Saturday, Nov. 17, 2012 file photo abortion rights protesters holding pictures of Savita Halappanavar march through central Dublin, demanding that Ireland's government ensures that abortions can be performed to save a woman's life. (AP Photo/Shawn Pogatchnik, File)

  • In this Saturday, May 4, 2013 file photo thousands of Roman Catholics take part in a Rosary Procession at Knock Shrine, Ireland. (AP Photo/Peter Morrison, File)

  • A Saturday, Nov. 17, 2012 photo from files showing abortion rights protesters hold candles and pictures in a vigil for Savita Halappanavar outside Ireland's government headquarters in Dublin. (AP Photo/Shawn Pogatchnik, File)

  • A Saturday, Nov. 17, 2012 photo from files showing several thousand abortion rights protesters marching through central Dublin, demanding that Ireland's government ensures that abortions can be performed to save a woman's life. (AP Photo/Shawn Pogatchnik, File)

  • A protester opposed to abortion demonstrates outside the Marie Stopes clinic in Belfast, Northern Ireland, Thursday, 18, 2012. (AP Photo/Peter Morrison)

  • Protesters opposed to abortion hold placards outside the Marie Stopes clinic in Belfast, Northern Ireland, Thursday, 18, 2012. (AP Photo/Peter Morrison)