HARRISBURG, Pa. — For most of his 30 years as Pennsylvania’s longest-serving U.S. senator and prominent moderate in Congress, Arlen Specter was a Republican, though often at odds with the GOP leadership.

He helped end the Supreme Court hopes of former federal appeals Judge Robert H. Bork, who was nominated by Ronald Reagan. Decades later, he was one of only three Republicans in Congress to vote for President Barack Obama’s stimulus.

His breaks with his party were hardly a surprise: He had begun his political career as a Democrat and ended it as one, too.

In between, he was at the heart of several major American political events. He rose to prominence in the 1960s as an assistant counsel to the Warren Commission, developing the single-bullet theory in President John F. Kennedy’s assassination. He came to the Senate in the Reagan landslide of 1980 and was a key voice in the confirmation hearings of both Bork and Clarence Thomas.

Specter died Sunday died at his home in Philadelphia from complications of non-Hodgkin lymphoma, said his son Shanin. He was 82. Over the years, Specter had fought two previous bouts with Hodgkin lymphoma, overcome a brain tumor and survived cardiac arrest following bypass surgery.

Intellectual and stubborn, Specter took the lead on a wide spectrum of issues and was no stranger to controversy.

In one of his last major political acts, Specter startled fellow senators in April 2009 when he announced he was joining the Democrats. He said he was “increasingly at odds with the Republican philosophy,” though he said the Democrats could not count on him to be “an automatic 60th vote” that would give them a filibuster-proof majority.

He had also concluded that he was unlikely to win a sixth term as a Republican, and his frankness about why he returned to the Democratic Party was packaged in a powerful TV ad by his primary opponent, then-U.S. Rep. Joe Sestak, who hammered away at the incumbent as a political opportunist.

“My change in party will enable me to be re-elected,” Specter says in TV news footage used in the ad.

And Democrats picked Sestak, a retired Navy vice admiral, over Specter in the 2010 primary, ending his decades of service. Sestak lost Specter’s seat to conservative Republican Rep. Pat Toomey in the general election by 2 percentage points.

Specter rose to prominence in the 1960s as an aggressive Philadelphia prosecutor and during his time on the Warren Commission.

In 1987, Specter helped thwart Bork’s nomination to the Supreme Court, earning him conservative enemies who still bitterly refer to such denials as being “borked.” But four years later, Specter was criticized by liberals for his tough questioning of Anita Hill at Clarence Thomas’ Supreme Court nomination hearings and for accusing her of committing “flat-out perjury.” The interrogation, televised nationally, incensed women’s groups and nearly cost him his seat in 1992.

Specter took credit for helping to defeat President Bill Clinton’s national health care plan — the complexities of which he highlighted in a gigantic chart that hung on his office wall for years afterward — and helped lead the investigation into Gulf War syndrome, the name given to a collection of symptoms experienced by veterans of the war that include fatigue, memory loss, pain and difficulty sleeping. And following the Iran-Contra scandal, Specter pushed legislation that created the inspectors general of the CIA, which later exposed Aldrich Ames as a Soviet spy.

But he was not afraid to buck his fellow Republicans.

As a senior member of the powerful Appropriations Committee, Specter pushed for increased funding for stem-cell research, breast cancer and Alzheimer’s disease, and supported several labor-backed initiatives in a GOP-led Congress. He also doggedly sought federal funds for local projects in his home state.

In 1995, he launched a presidential bid, denouncing religious conservatives as the “fringe” that plays too large a role in setting the party’s agenda. Specter, who was Jewish, bowed out before the first primary because of lackluster fundraising.

Specter’s irascible independence caught up with him in 2004. He barely survived a GOP primary challenge from Toomey by 17,000 votes of more than 1.4 million cast. He went on to easily win the general election with the help of organized labor, a traditionally Democratic constituency.

Specter was diagnosed in 2005 with stage IV Hodgkin lymphoma, a cancer of the lymphatic system. Announcing the diagnosis with his trademark doggedness, Specter said: “I have beaten a brain tumor, bypass heart surgery and many tough political opponents and I’m going to beat this, too.”

“Arlen Specter was always a fighter,” Obama said in a statement Sunday. “From his days stamping out corruption as a prosecutor in Philadelphia to his three decades of service in the Senate, Arlen was fiercely independent — never putting party or ideology ahead of the people he was chosen to serve. He brought that same toughness and determination to his personal struggles.”

Specter wrote of his illness in a 2008 book, “Never Give In: Battling Cancer in the Senate,” saying he wanted to let others facing similar crises “ought to know they are not alone.”

Cancer handed him “a stark look at mortality” and an “added sense of humility,” Specter told The Associated Press.

Born in Wichita, Kan., on Feb. 12, 1930, Specter spent summers toiling in his father’s junkyard in Russell, Kan., where he knew another future senator — Bob Dole. The junkyard thrived during World War II, allowing Specter’s father to send his four children to college.

Specter left Kansas for college in 1947 because the University of Kansas, where his best friends were headed, did not have Jewish fraternities. He graduated from the University of Pennsylvania in 1951 and Yale law school in 1956. He served in the Air Force from 1951 to 1953.

Friends say his childhood circumstances made him determined, tough and independent-minded. Specter considered his father’s triumphs the embodiment of the American dream, a fulfillment that friends say drove him to a career in public life.

He entered politics as a Democrat in Philadelphia in the early 1960s, when he was an assistant district attorney who sent six Teamsters officials to jail for union corruption.

Working on the Warren Commission in 1964, Specter was the chief author of the theory that a single bullet had hit both Kennedy and Texas Gov. John Connally, an assumption critical to the conclusion that presidential assassin Lee Harvey Oswald acted alone. The theory remains controversial and was the subject of ridicule in Oliver Stone’s 1991 movie “JFK.”

After working on the Warren Commission, he returned to Philadelphia and challenged his boss, James Crumlish, for district attorney in 1965. Specter ran as a Republican and was derided by Crumlish as “Benedict Arlen.” But Crumlish lost to his protege by 36,000 votes.

Specter lost re-election as district attorney in 1973 and went into private practice. Among his most notorious clients as a private attorney was Ira Einhorn, a Philadelphia counterculture celebrity who killed his girlfriend in 1977.

After leaving the Senate in January 2011, the University of Pennsylvania Law School said Specter would teach a course about Congress’ relationship with the Supreme Court, and Maryland Public Television launched a political-affairs show hosted by the former senator.

He also occasionally performed standup comedy at clubs in Philadelphia and New York. He played squash nearly every day into his mid-70s and liked to unwind with a martini or two at night.

A funeral was scheduled for Tuesday in Penn Valley, Pa., and will be open to the public, followed by burial in Huntingdon Valley, Pa.

Specter is survived by his wife, Joan, and two sons, Shanin and Steve, and four granddaughters.