Bruce L. Castor Jr. finally got the job he always wanted. And two weeks in, he's about to lose it.

His unexpected rise to attorney general - and looming departure from the post - tops off a whirlwind eight months for the cowboy boot-wearing Republican. And has him facing the end of his political career for the second time in a year.

After decades as a Montgomery County prosecutor and commissioner, he lost a bitter race to reclaim his job as district attorney. The usually camera-friendly Castor faded from view after Bill Cosby's December arrest, even warning reporters on Facebook that they may encounter "Mr. Ruger" - as in the handgun - if they knocked on his door for comment about his 2005 decision not to pursue the case.

Then, with the stroke of a pen by beleaguered Attorney General Kathleen Kane, he became her top legal adviser, paving the way for him to replace her when she was convicted and resigned this month.

"He always said attorney general was the real job that he coveted," said Brian Miles, a longtime friend. "And he's accomplished it. He's gotten there - through the most ridiculously improbable road - but he got there."

Castor may not keep the job for long.

Gov. Wolf has nominated his own replacement, Bruce Beemer, to serve out Kane's term while she awaits sentencing for perjury and obstruction. The Senate is poised to approve Beemer as soon as Tuesday.

But those who have seen it say Castor's path back into the limelight, and the impact he's had in just a few months, may go down as one of the more amazing political stories in the state's recent history.

And yet, not entirely unexpected.

"Nothing about Bruce could surprise me anymore," said Joseph M. Hoeffel, a Montgomery Democrat who served and often clashed with Castor on the board of county commissioners. "He's a big personality and, well . . . there it is."

On board

Two days after his Aug. 17 swearing in as acting attorney general, Castor, 54, sat in his Ardmore law office ruminating on his past, present and future.

He said he was disappointed that the governor would not let him stay in office longer - "I doubt that there's anybody in all of Pennsylvania that has more experience and brings more knowledge to the game than me," he had declared after Kane's conviction - but that he respected the process.

Besides, in his view, his tenure lasted not days, but months, all the way back to March, when a strange political alliance was born.

With her law license suspended as she awaited trial, Kane lacked support within her own party, and even inside her office. So she arranged a meeting with Castor.

"I deduced that the only thing that she'd want to see me about would be defending her in her criminal case," he said, recalling their meeting. "I began thinking about how much I was going to charge to take that case, and I was totally taken by surprise that she was effectively asking me to come on and run the office."

She bestowed on him the title of "solicitor general," answering only to her.

Quickly he became her surrogate, making legal decisions for the office that rippled statewide.

His first bombshell came in April. In an unexpected move in a four-year legal war, Castor declared that state prosecutors would not fight to reinstate charges against three Pennsylvania State University administrators accused of ignoring or covering-up Jerry Sandusky's serial sexual abuse.

Then, at a June state Senate hearing, he infuriated House members and advocates for sex-abuse victims when he declared unconstitutional a House-backed bill that would have allowed victims to sue their childhood abusers for decades-old attacks - an opinion that bolstered critics of the bill and may have stemmed a wave of lawsuits against the Catholic Church.

Even as her top aide, he wielded his authority in ways Kane may have not intended. In May, Castor canceled a news conference she had planned to release results of an independent investigation she commissioned into the exchange over state computers of pornographic or inappropriate emails. (Late last week, as word bubbled that the report was done and would name hundreds of people, Castor again signaled that it would not yet be released.)

The Cosby case

All the while, Castor still remains a polarizing figure and potential witness in the Cosby prosecution.

After word emerged last summer that county prosecutors had revived the decade-old investigation into Cosby's alleged assault of Andrea Constand, attention also started building on Castor's decision to drop that case when he led the office.

Castor gave public interviews defending his decision; Constand and her lawyers sued him for defamation.

His decision became a central pillar in the fall campaign battle with Kevin Steele, the lead prosecutor on the Cosby case and Democrats' choice for Montgomery County District Attorney.

And after Steele won the election and charged Cosby, Castor testified for the entertainer's defense in February, insisting he had made a binding promise to Cosby's lawyer that he would never be prosecuted for the crime.

At a Norristown hearing, Castor called himself "the sovereign of the commonwealth of Pennsylvania" while explaining the purported non-prosecution agreement, and told the judge he had too many achievements and awards to list without submitting a full resume.

Earlier this month, Castor poked his head into another Steele case: Kane's trial. He questioned whether the star prosecution witness, who testified under an immunity order, could still face prosecution.

He later said he never intended to inject himself into the case. "I was looking into it to see if I was right on the law" about immunity, he said, adding, "I am right on that."

And seconds after the jury announced its verdict against Kane, Castor burst through the doors of the courtroom in his signature pinstripe suit, whispered with a sheriff's deputy, and settled onto a bench in the gallery.

Quick rise

Such swagger is typical of Castor, whose career began with a quick rise in the District Attorney's Office. He once won five first-degree murder convictions in a year. Others admired his courtroom skills. They also noticed that he thrived on publicity.

"We used to make fun of him for it," said David Keightly, a district judge who worked with him as a prosecutor. "He was good at it, but he seemed to like the cameras more than the rest of us."

Castor ran for attorney general in 2004, later describing himself as "seduced" by the allure of statewide office.

"I knew that I would do a good job and that I would be then the nominee for governor," he said in an interview last year.

But he lost the Republican primary for attorney general to Tom Corbett. If he had won, he still maintains, he would be the current governor.

He also began feuding with members of his own party. Despite getting the most votes in the 2007 county commissioner's race, Castor found himself sidelined by former Commissioner James R. Matthews, a fellow Republican who formed a cross-party, power-sharing alliance with Hoeffel, a Democrat. The trio's public meetings often devolved into bouts of name-calling and acrimony.

Castor remained the minority commissioner when two Democrats won control of the county in his second term. But he got along well with them.

Josh Shapiro, the chairman, is the Democratic nominee for attorney general against Republican Sen. John Rafferty, also of Montgomery County. Calling them both personal friends, Castor said he had hoped to remain as attorney general until after the election, and that he'd be happy to work for either during a transition.

He knew his days were numbered, but Castor moved quickly last week to cement his legacy, dropping the "acting" designation that others might use from news releases and the office website.

"I thought it was appropriate to use the title," he said, "and I'm going to keep doing it."

Miles, chairman of the Whitpain Republicans, describes his friend as misunderstood and, at times, "his own worst enemy" because he did not debunk others' perception of him as arrogant and aloof. But the title, he said, is Castor's to keep.

"When his obituary is written it's going to say Pennsylvania Attorney General," Miles said. "Whether he was attorney general for a week or a month or a year, it doesn't really matter."

Charlie Gerow, a Harrisburg-based consultant and observer of state politics, acknowledged that "it's something of an anomaly" to hold statewide office for such a short time. But, he said, "By all accounts [Castor] did a good job under trying conditions."

As he sat in his office, surrounded by photos and awards and reflecting on the end of an unlikely chapter in his career, Castor seemed subdued.

By late last week, he was resigned. "My wife and I had champagne last night to celebrate that it is almost over," he wrote in an email Friday.

"The last two weeks have convinced me that while I enjoyed to work at OAG, I enjoy the environment more back home. I wish everyone all the best who wants to get to or continue in Harrisburg."

610-313-8116

@Lmccrystal

Staff writer Jeremy Roebuck contributed to this article.