HARRISBURG - Election boards in Pennsylvania's 67 counties are poised to start recounting hundreds of thousands of ballots in a tightly contested statewide judicial primary race.

Secretary of the Commonwealth Carol Aichele on Thursday ordered a mandatory recount in the Democratic primary election for Commonwealth Court judge.

Doylestown lawyer Kathryn Boockvar beat her opponent, Barbara Behrend Ernsberger, a Pittsburgh lawyer, by 2,116 votes in the May 17 election.

The margin of victory was below one half of 1 percent of the total vote - the threshold for triggering an automatic recount under the law.

Ernsberger said she decided not to waive her right to a recount so Democratic voters would have a clear decision on who won.

"I believe the legislature put the recount mechanism in here so that everyone knows the results," Ernsberger said. "There can be mistakes in counting, and this recognizes a race this close should be recounted."

County election boards must now begin the labor-intensive process of counting 621,132 ballots.

Boockvar said she was confident she would prevail and thought spending hundreds of thousands of dollars to conduct a recount with margins of several thousand votes was a burden on election officials and taxpayers.

"If we were 50 votes apart, I'd understand, but the patterns of the last decade show differently," she said. "No similar races have been changed as a result."

Aichele said the recount ensured government openness and accountability.

"There is nothing more important to our system of government than a transparent election process in which our citizens have confidence," she said in a statement.

The last statewide recount - in a November 2009 Superior Court race - cost the state $542,000.

By law, the results of the current recount must be presented to the Department of State by June 8.

Contact staff writer Amy Worden at 717-783-2584 or aworden@phillynews.com.