The November election for Pennsylvania attorney general will be a race between two Montgomery County candidates.

Republican John Rafferty and Democrat Josh Shapiro easily won their respective primaries Tuesday, according to unofficial results. The men are vying to replace Attorney General Kathleen Kane, who chose not to seek reelection as she prepares for a criminal trial this year. Kane's indictment shaped the primary race, one dominated by candidate promises to clean up the high-profile dysfunction in the office.

In the more bitterly contested Democratic primary, Shapiro defeated Allegheny County District Attorney Stephen Zappala Jr., with Northampton County District Attorney John Morganelli finishing in a distant third place.

Shapiro, chairman of the Montgomery County Board of Commissioners, faced attacks for his lack of prosecutorial experience. But he gathered big-name endorsements, from President Obama, Gov. Wolf, and U.S. Sen. Bob Casey Jr.

Taking the stage, with a group of elected officials who endorsed him, after 11 p.m. at the Double Tree hotel in King of Prussia, Shapiro vowed to reform the criminal justice system.

"Too many Pennsylvanians believe that the system is rigged against them," he said. "I fundamentally believe that Pennsylvania needs real reform."

Zappala, a longtime district attorney, had name recognition - his father was a state Supreme Court chief justice - and endorsements from Philadelphia Mayor Kenney, the Philadelphia Democratic City Committee, and Lt. Gov Mike Stack III.

The race grew particularly tense in the final days, as Shapiro and Zappala traded attacks and television ads. Both Zappala and Morganelli called Shapiro to concede Tuesday night.

"He had a very masterful campaign," Morganelli said in a phone interview as votes came in. "He had a lot of institutional support and lots of money."

Rafferty, who has the endorsement of the state Republican party, defeated Joe Peters of Wyoming County. He is serving his fourth term in the state Senate and lives in Audubon, where he gathered with supporters at Chadwick's at the Club at Shannondell on Tuesday night.

"I'm very happy," Rafferty said in a phone interview from his election night gathering, adding that he looked forward to working to "restore integrity and professionalism" to the office.

Peters, a former organized-crime prosecutor, spent 17 years in the attorney general's office. He most recently worked there under Kane, until he resigned in 2014.

Rafferty was the first candidate of either party to run, announcing last June that he wanted to clear up the "black cloud" over Kane's office.

Kane, a Democrat elected in 2012, faces an August trial in Montgomery County on perjury and other crimes for allegedly leaking secret grand jury materials and lying about it.