LINCOLN, Neb. — Nebraska became the first conservative state in more than 40 years to abolish the death penalty Wednesday, with lawmakers defying their Republican governor, Pete Ricketts, a supporter of capital punishment who had lobbied against banning it.

After more than two hours of emotional speeches at the Capitol here, the Legislature, by a 30-19 vote that cut across party lines, overrode the governor’s veto of a bill repealing the state’s death penalty law.

After the repeal measure passed — by just enough votes to overcome the veto — dozens of spectators in the balcony burst into celebration.

The vote capped a months-long battle that pitted most lawmakers in the unicameral Legislature against the governor, many law enforcement officials, and some family members of murder victims whose killers are on death row. The Legislature approved the repeal bill three times this year, each time by a veto-proof majority, before sending it to Ricketts’ desk. Adding to the drama, two senators who had previously voted for repeal switched to support the governor at the last minute.

Opponents of the death penalty here were able to build a coalition that spanned the ideological spectrum by winning the support of Republican legislators who said they believed capital punishment was inefficient, expensive, and out of place with their party’s values, as well as that of lawmakers who cited religious or moral reasons for supporting the repeal. Nebraska joins 18 other states and Washington, DC, in banning the death penalty.

Although it is not clear that other Republican-dominated states will follow Nebraska’s example, Wednesday’s vote came at a time when liberals and conservatives have been finding common ground on a range of criminal justice issues in Washington and around the country. In other states, Democrats and Republicans driven by different motivations have formed alliances to limit the revenue that towns can collect from traffic fines; to crack down on civil asset forfeiture, a practice that disproportionately affects the poor; and to ease mandatory prison sentences.

On the presidential trail, Hillary Rodham Clinton and Sens. Ted Cruz and Rand Paul have all called for easing mandatory minimum sentences, while other Republican candidates have embraced proposals to revamp bail and expand drug treatment that have also been championed by Democrats.

Though it formally considers itself nonpartisan, the Nebraska Legislature is dominated by Republicans.

Ricketts, who fought against the repeal bill by appearing repeatedly in television interviews and urging Nebraskans to pressure their senators to oppose it, immediately denounced the vote.

“My words cannot express how appalled I am that we have lost a critical tool to protect law enforcement and Nebraska families,” he said in a statement. “While the Legislature has lost touch with the citizens of Nebraska, I will continue to stand with Nebraskans and law enforcement on this important issue.”

In a debate that was by turns somber, fiery, and soul-searching, with sprinklings of quotes from Ruth Bader Ginsburg, John Paul Stevens, and the Book of Genesis, senators stood to make last-minute pitches to try to persuade the undecided. Some said capital punishment should be retained as a tool to punish the most heinous crimes. Others said the death penalty, which has not been used in Nebraska since 1997, was irretrievably broken.

“Today we are doing something that transcends me, that transcends this Legislature, that transcends this state,” said Sen. Ernie Chambers, an independent from Omaha who sponsored the bill and has fought against the death penalty for decades. “We are talking about human dignity.”

A few senators argued Nebraskans were still broadly in favor of capital punishment, even if many Republicans in the Legislature had turned away from it. Others said they were deeply conflicted about their vote to retain the death penalty.

“Today I will sustain the governor’s veto because I campaigned on it,” said Sen. Tyson Larson, two hours into the debate. “This might be the last time I give the state the right to take a life because I don’t think that they necessarily should.”

The bill replaces capital punishment with life imprisonment.

The vote Wednesday came a day after Ricketts signed a veto of the death penalty repeal bill in front of reporters assembled at the Capitol and talked about a gruesome bank robbery in the city of Norfolk in 2002, in which five people were shot to death, as a compelling reason that Nebraska should hold on to capital punishment. Two family members of a woman who was shot during the robbery stood at the governor’s side.

Some Nebraskans said in interviews this week they agreed with the governor.

“I’m sure small-town, rural Nebraska communities are furious about the repeal,” said Chris Spargen, a project specialist in his mid-20s, as he rode his bike down a main thoroughfare in Ashland, 30 miles outside Omaha. “I guess I’m technically falling under that as well.”

In downtown Ceresco, about 18 miles north of Lincoln, Wayne Ambrosias, owner of the Sweet Pea Market, said he did not want his tax dollars used to pay for murderers to stay in prison for their entire lives. And he echoed the governor’s statement that the lawmakers who supported the death penalty repeal were out of touch with a widely conservative public.

“I don’t think the politicians are in line with the everyday people,” Ambrosias said Wednesday just before the vote. “I think it’s more of a political move. I don’t think the people are telling them that’s what they want.”

But others said they saw the issue differently, rejecting the argument that the death penalty was necessary to deter crime.

“A lot of times murder is a crime of passion,” said Don Johnson, a retired commercial fisherman from Alaska now living in Ceresco. “I don’t think they think about the death penalty when they kill somebody or somebody gets killed. I don’t think it’s a preventative measure at all.”

Johnson, who considers himself an evangelical Protestant, said he saw the issue less as a religious belief than a strictly personal one. Other members of his church are in favor of the death penalty, he said, though he admitted he could not quite reconcile the punishment with Christianity.

“If you really follow Jesus’ teachings,” he said, “thou shall not kill, you know.”

Catholic bishops in Nebraska issued a statement Tuesday criticizing Ricketts’ veto.

“We remain convinced that the death penalty does not deter crime, nor does it make Nebraska safer or promote the common good in our state,” they said.

Since 2007, six states have abolished the death penalty: Maryland, Connecticut, Illinois, New Mexico, and New Jersey. According to the Death Penalty Information Center, a research group opposed to the death penalty, no conservative state has banned capital punishment since North Dakota in 1973. The center defines a conservative state as having voted Republican in the two most recent presidential elections.

Across the country, efforts to execute criminals on death row have stalled in the face of growing backlash against the death penalty and logistical difficulties with lethal injections. Many states have had difficulty obtaining lethal injection drugs, as European manufacturers, citing moral and ethical objections, have refused to sell them to prisons in the United States. Texas, which executes more inmates than any other state, has only enough drugs to carry out one more lethal injection.

Searching for alternatives in the face of drug shortages, some states have taken other measures. In March, Utah’s governor signed a law allowing firing squads to be used for executions, and Arkansas, Wyoming, and Idaho have considered replacing lethal injection with firing squads.

Ricketts tried to ward off concerns about the availability of drugs by announcing this month that he had made arrangements with a pharmaceutical company to obtain the necessary drugs for lethal injections. Some lawmakers have said that the governor had not actually obtained the drugs, asserting that he was trying to sway legislators to uphold his veto. Those lawmakers have also raised questions about whether those drugs would be legal to use, if the governor had obtained them.