Siding with state elections officials Monday, a circuit judge allowed them to proceed with Maryland’s forthcoming primary with ballots that do not include the name of Valerie Ervin, the last-minute Democratic candidate for governor.

Ervin’s name will appear instead on ballots as the running mate of the late Kevin Kamenetz, the former Baltimore County executive who had been one of the leading contenders in the June 26 Democratic primary before dying of a heart attack in early May.

Anne Arundel County Circuit Judge William C. Mulford said making a change to millions of ballots with just over a week until early voting begins threatened to cause more confusion than allowing for the rare appearance on the ballot of a deceased candidate and his running mate.

“I just can’t imagine turning this election upside down,” Mulford said as he ruled on Monday.

Ervin, a former Montgomery County councilwoman, said after the ruling that she had not decided whether to appeal. Last week she filed her lawsuit to force state officials to reprint primary election ballots with her name on them.

“The voters lost today,” Ervin said. “We really do believe that voters are going to be confused and we need to do all that we can to support their right to vote and to be clear about who it is that they’re voting for.”

After Kamenetz died on May 10, Ervin took the option the next week of running in his place and named Marisol Johnson, a former Baltimore County school board member, as her running mate.

Although Ervin made her decision within the time frame allowed by state law, Maryland elections officials concluded there wasn’t enough time to reprint ballots before early voting begins on June 14.

Instead they have been circulating notices letting Democratic primary voters know that ballots cast for Kamenetz will count for Ervin.

A lawyer for the state elections board and an expert witness called by Ervin both concluded that a full reprinting of as many as 3.7 million ballots was impossible by Monday.

But Ervin’s lawyers asked the judge to order that stickers with her name be placed on ballot papers — an option permitted by state law. Mulford rejected that idea as untested.

“I can’t speculate,” the judge said. “I can’t guess if stickers would work.”

Mulford ruled that Linda H. Lamone, the state elections administrator, had handled the situation in accordance with the law and the Maryland and U.S. Constitutions.

Referring to documents filed in the case and Monday’s testimony, Mulford ran through the steps Lamone had taken almost as soon as she learned Kamenetz had died and concluded, “The court cannot find any of those actions were unreasonable.”

Mulford did express sympathy for Ervin’s desire to have her candidacy reflected on the ballot.

“I find myself some days sitting wishing I could do things I can’t,” he said. “I wish I could help you, but I just can’t.”

The Ervin case and another one decided in May that challenged the appearance of disgraced former-Sen. Nathaniel T. Oaks’ name on ballots have highlighted the difficulty state officials face in responding to changes as elections draw near. Oaks resigned from the Senate and pleaded guilty to two federal corruption charges in March. He backed efforts to remove his name from ballots.

Asked by Ervin’s lawyer how quickly officials could reprint ballots and have them ready for voters to use, Lamone said, “I think at least 45 days.”

Lamone said she had given little thought for preparing to reprint ballots or keeping extra paper in stock because she knew the law gave her options to rely on in an emergency.

Mariana Cordier, Ervin’s attorney, seized on that testimony in a searing final argument to the judge.

“The state board of elections has woefully failed in its obligations,” Cordier said.

The only example Cordier cited of ballots being reprinted in Maryland happened in a 1978 congressional race when a candidate died and his wife ran in his place. The state’s election system has changed dramatically since then.

Cordier said after the hearing that the case exposed flaws in the state’s election laws that give officials too much power to make decisions. She said the General Assembly should clarify them.

Before Ervin filed her lawsuit, elections officials said the state’s ballot counting machines rely on special paper that is produced at a single mill, which was out of stock until the week of Election Day.

During the hearing, Lamone testified that she had explored using different paper but even then the state’s printing contractors said they couldn’t produce ballots until June 11 at the earliest. Lamone said at that point the ballots still would need weeks of testing to make sure they worked properly.

State law allows elections administrators to put stickers on ballots to reflect late changes. But officials ruled out the option. Lamone said the election machine manufacturer had recommended strongly against using stickers and said that trying them was too risky.

“You’re asking approximately two million stickers to be applied accurately,” Lamone said.