Maryland Gov. Martin O'Malley (Nikki Kahn/THE WASHINGTON POST)

Outgoing Gov. Martin O’Malley (D) on Wednesday cemented his legacy on a defining issue of his tenure, announcing that he would commute the sentences of Maryland’s four remaining death-row inmates to life in prison without the possibility of parole.

With the stroke of a pen, O’Malley will soon wipe out the remnants of capital punishment in Maryland, an issue on which he lobbied lawmakers from the outset of his first term in 2007. A practicing Catholic, O’Malley argued that executions are not cost-effective, do not deter murders and are at odds with “our values as a people.”

O’Malley’s decision to commute the death sentences comes nearly two years after he persuaded the legislature to repeal capital punishment and three weeks before he will complete his second, and final, term.

The repeal did not apply to prisoners already on death row, leaving their fate up in the air. In November, Attorney General Douglas F. Gansler said he believes the state lacks any legal way to execute them, citing an earlier court ruling that invalidated state procedures for administering lethal injections.

“In my judgment, leaving these death sentences in place does not serve the public good of the people of Maryland — present or future,” O’Malley said in a statement Wednesday.

The abolishment of the death penalty was one of several progressive accomplishments for O’Malley, a potential 2016 White House candidate, including the legalization of same-sex marriage and sweeping gun-control measures.

Randy Piechowicz, a relative of one of the inmates’ victims, said his family “had been hopeful that one day the political climate would change and these sentences would be carried out and justice would be served.”

O’Malley’s decision, he said, “is the bitter end to a most horrible family tragedy.”

Gov.-elect Larry Hogan (R) said Wednesday that he was “not in a place to second-guess what is probably one of the most difficult decisions a governor may have to make.”

In announcing his decision — which will take effect just days before he leaves office — O’Malley cited the recent opinion from Gansler (D) that death sentences could no longer be carried out in Maryland because there is no death penalty statute on the books and no procedures in place for administering executions. There were five death-row inmates when the repeal legislation took effect; one has died of natural causes.

O’Malley said the death sentences of inmates Vernon Evans, Anthony Grandison, Jody Lee Miles and Heath Burch were “un-executable” and expressed hope that the commutations would bring “a greater degree of closure for all of the survivors and their families.”

The governor spoke privately in recent weeks with many relatives of those killed by the inmates, and some of the relatives pleaded with him not to use his executive powers to alter court decisions. On Wednesday, those family members joined some prosecutors in sharply criticizing O’Malley’s decision.

“I’m not disappointed. I’m devastated,” said Mary F. Moore, 71, whose father and stepmother were slain in 1995 by Burch, their neighbor. Burch attacked Robert and Cleo Davis with a pair of scissors in their Capitol Heights home. At the time, Burch was reportedly high on crack cocaine and other drugs.

Moore, who urged O’Malley not to commute Burch’s sentence during a telephone conversation in November, said she had lost faith in the criminal justice system. “This man took away from this family people we respected and loved, and we miss them,” Moore said. “I feel like I could have had a few more years with them.”

Baltimore County State’s Attorney Scott D. Shellenberger (D), a death penalty proponent, also chastised O’Malley. “I think it’s interesting that with 21 days left in the administration that he decides to show mercy for two calculating killers,” he said, referring to Evans and Grandison, who were convicted in his jurisdiction. “I think these are valid sentences, and they should be carried out.”

Evans and Grandison were sentenced to death in 1984 for the contract killing of David Scott Piechowicz and Susan Kennedy in Baltimore County. Piechowicz and his wife, Cheryl, had been scheduled to testify against Grandison in a federal drug trial and were the target of a hit for which Grandison paid Evans $9,000.

Jane Henderson, former executive director of Maryland Citizens Against State Executions, said she was sympathetic to the anguish of the victims’ families. But in the wake of Gansler’s opinion, she said, there was virtually no chance that the state’s four death-row inmates would be put to death. O’Malley’s decision to commute the four sentences, she said, closes the books on the issue: “The death penalty really is gone now in Maryland.”

Del. Samuel I. Rosenberg (D-Baltimore), a longtime death-penalty opponent, stressed that none of the death-row inmates would ever be released under the sentence that will be assigned by O’Malley.

O’Malley may not have the final word on all of the inmates’ sentences, however. Attorneys for Miles are trying to get an appeals court to change his death sentence to life with the possibility of parole. In a statement Wednesday, the lawyers asked O’Malley to reconsider his action and said that if he doesn’t, “there likely would be further litigation challenging his authority.”

Gansler said he was confident such a claim would not prevail.

O’Malley’s action comes at a time when fewer states are executing inmates and fewer people are being sentenced to death.

In 2014, the United States executed 35 inmates, the fewest in two decades. The number of people sentenced to death in 2014 was 72, according to the Death Penalty Information Center, compared with about 300 a year in the mid-1990s. Maryland was one of six states to ban the death penalty between 2007 and 2013.

A Washington Post-ABC News poll in June found that 60 percent of Americans favor the availability of the death penalty for people convicted of murder. Support is much lower than in the 1980s and 1990s but has remained relatively stable in recent years. At the same time, Americans are more evenly split on whether they prefer life without the possibility of parole to the death penalty.

As his time as governor comes to an end, O’Malley has taken action on several long-simmering issues, including issuing executive orders on some key environmental matters. And on Tuesday, he appointed 10 district and circuit court judges.

O’Malley spokesman Ron Boehmer said the governor’s office plans to issue a notice of O’Malley’s intentions on Monday in the Daily Record, a Baltimore-based legal publication. That will run for two weeks, he said.

Sometime after Jan. 19, before he leaves office on Jan. 21, O’Malley plans to issue an executive order commuting the death sentences, Boehmer said.

“Gubernatorial inaction — at this point in the legal process — would, in my judgment, needlessly and callously subject survivors, and the people of Maryland, to the ordeal of an endless appeals process, with unpredictable twists and turns, and without any hope of finality or closure,” O’Malley said.

Antonio Olivo and Mark Berman contributed to this report.