Former senator Arlen Specter of Pennsylvania, one of the nation’s most durable political figures who during three decades in the Senate became known for his command of constitutional law, died of cancer on Sunday at his home in Philadelphia. He was 82.

The death was confirmed by Scott Hoeflich, Sen. Specter’s former chief of staff.

Sen. Specter was long a voice of Republican moderation, but he handed Democrats a supermajority in the Senate by switching parties in 2009. He lost the Democratic primary the next year in an anti-incumbency movement that swept many veteran politicians from office. He had also exposed himself to charges of political opportunism by changing his party allegiance.

As a young Philadelphia prosecutor, he first gained national attention as assistant counsel to the Warren Commission, which investigated the 1963 assassination of President John F. Kennedy. He was the chief architect of the commission’s controversial “single-bullet theory,” which held that the same bullet that killed Kennedy also wounded then-Texas Gov. John Connally.

Sen. Specter parlayed the exposure he received on the commission into a political career, first as a combative and outspoken Philadelphia district attorney and then as a five-term U.S. senator.

“Arlen Specter was always a fighter,” President 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.”

Arriving on Capitol Hill in 1981, Sen. Specter became a dominant force during the Judiciary Committee’s rancorous Supreme Court nomination battles. More than anyone else, he helped defeat conservative nominee Robert Bork in 1987, and his aggressive questioning of law professor Anita Hill four years later — he accused her of “flat-out perjury” — helped secure Clarence Thomas’s confirmation.

Sen. Specter was respected for his well-prepared and persuasive arguments that were rooted in the law rather than in political expediency. He sided with liberals on some divisive issues and with conservatives on others, leaving him with little support on either end of the spectrum.

He consistently drew challenges from the left and the right in his centrist state, and his career was marked by narrow victories. “I had a rocky road getting here,” he once said, “and I’m going to do my damnedest to stay here.”

In 2009, Sen. Specter was one of three Republicans who negotiated with Senate Democrats over President Obama’s economic stimulus bill, but his vote for the $787 billion measure left him politically vulnerable among Pennsylvania’s unpredictable electorate.

“I believe that my duty is to follow my conscience and vote what I think is in the best interest of the country, and the political risks will have to abide,” Sen. Specter said at the time.

Acknowledging that he could not win his 2010 reelection battle against Republican primary challenger Patrick J. Toomey, the former head of the conservative Club for Growth, Sen. Specter switched parties. He became the 60th Democratic senator, giving Obama’s party a filibuster-proof majority. But he immediately drew a primary challenge from Rep. Joe Sestak, whose run from the left forced Sen. Specter to assert liberal positions on issues such as health-care reform.

Sen. Specter was the rare lawmaker who catered to the interests of his state while also playing a starring — and often controversial — role in fractious debates over important national issues.

“Arlen Specter may be the most masterful politician in the history of this state,” said G. Terry Madonna, a political scientist at Franklin and Marshall College in Lancaster, Pa. “He won’t be outworked, he won’t be out-hustled, and he understands his state better than any other politician in modern history.”

The longest-serving senator in Pennsylvania history, Sen. Specter aged dramatically while in public office, suffering serious health problems over the years. He survived bouts with benign brain tumors in 1993 and 1996, and then cancer in the form of Hodgkin’s disease in 2005 and 2008. Despite his medical issues, he never missed a Senate session, and he co-wrote a book on the subject in 2008 called “Never Give In: Battling Cancer in the Senate.”

Sen. Specter was one of Congress’s leading champions of medical research. Together with Sen. Tom Harkin (D-Iowa), he helped double the National Institutes of Health budget from 1999 to 2004. He was a vocal supporter of federal funding for embryonic stem cell research, which is opposed by many conservatives because it uses excess human embryos from in-vitro fertilization. Sen. Specter also supported abortion rights and was a steady backer of Obama’s health-care overhaul agenda.

Although admired by colleagues for his policy knowledge and political conviction, Sen. Specter had a reputation for being arrogant, even irascible. He was famously short-tempered and sharp-tongued, earning the Capitol Hill sobriquet “Snarlin’ Arlen.”

‘A liberal Republican’

When Sen. Specter arrived in the Senate, he found a home among moderate Republicans, often voting with Democrats. He supported the death penalty and opposed most gun-control measures, but he favored affirmative action and voted against some tax cuts for wealthier Americans. He also was a leader in strengthening civil rights laws.

“He was a Rockefeller Republican, a liberal Republican, and was willing to take on Presidents Reagan and Bush, and became a true leader in the bipartisan efforts that strengthened all the civil rights laws and defeated Bork,” said Ralph G. Neas, a longtime civil rights and health-care advocate.

“Then you had a line of demarcation,” Neas said, beginning with Thomas’s Supreme Court nomination and continuing with the Republican majorities in the House and the Senate after the 1994 midterm elections. “Arlen Specter became an especially cautious politician,” Neas said.

When the Republicans took control of the Senate in 1995 with a new cast of conservatives, Sen. Specter was a leader of the moderate wing. He sought the party’s 1996 presidential nomination to challenge President Bill Clinton, arguing that the nation could not afford “a Republican candidate so captive to the demands of the intolerant right that we end up reelecting a president of the incompetent left.”

But he could not woo enough Republicans, and he suspended his campaign just before the primaries began, endorsing Sen. Robert J. Dole (Kan.).

In the years that followed, Sen. Specter’s breed of moderate Republicans vanished in Congress, and he became a more cautious politician. But he gained considerable influence after becoming chairman of the Judiciary Committee in 2005.

After Sen. Specter warned President George W. Bush not to nominate judges who would overturn Roe v. Wade — the 1973 Supreme Court case that essentially legalized abortion rights — conservative Republicans protested his appointment to the Judiciary Committee. Sen. Specter later said he would not use a “litmus test” to deny confirmation to abortion opponents.

He presided over the confirmations of Supreme Court Justices John G. Roberts Jr. and Samuel A. Alito Jr. and was a key force behind passage of some of the Bush administration’s controversial anti-terrorism laws, including the Patriot Act. But as controversy erupted over the government’s handling of detainees at Guantanamo Bay, Cuba, Sen. Specter became a leading proponent of habeas corpus rights for unlawful combatants.

And in 2007, when Bush’s attorney general, Alberto Gonzales, was accused of having political motivations in the firings of eight U.S. attorneys, Sen. Specter concluded that the Justice Department would be better off if Gonzales resigned.

A Kansas childhood

The son of Russian Jewish immigrants, Arlen Specter was born in Wichita on Feb. 12, 1930. He was raised in Russell, Kan., a farming town that was also home to Dole, the longtime Senate Republican leader who became one of Sen. Specter’s earliest political idols.

In 1951, Sen. Specter received a bachelor’s degree from the University of Pennsylvania, graduating with membership in Phi Beta Kappa. After two years of service in the Air Force, he graduated in 1956 from Yale Law School, where he edited the law journal. He spent three years as a private-practice lawyer in Philadelphia and in 1959 was appointed the city’s assistant district attorney.

In 1953, he married Joan Levy, who later served on the Philadelphia City Council. Besides his wife, of Philadelphia, survivors include two sons, Stephen Specter of Los Angeles and Shanin Specter of Lower Merion, Pa.; a sister; and four grandchildren.

After his service on the Warren Commission, Sen. Specter returned to Philadelphia to pursue a career in elected office. In 1965, he sought the Democratic nomination to be the city’s district attorney, but the party machine rebuffed him. A registered Democrat, he joined the Republican Party and, campaigning as the reform candidate, defeated his former boss, Democratic District Attorney James C. Crumlish Jr.

As the chief prosecutor, Sen. Specter was combative and outspoken, launching numerous high-profile investigations, taking on powerful interests and building his public reputation. In 1967, he was the Republican nominee for mayor but lost in a close race.

With his party damaged by fallout from the Watergate scandal, Sen. Specter lost reelection in 1973 and was unsuccessful in campaigns for the Senate and for governor later that decade. Undeterred, however, in 1980 Sen. Specter sought and won a Senate seat, which he held uninterrupted for 30 years. In 2011, he became an adjunct faculty member of the University of Pennsylvania Law School.

Paul Kane and Chris Cillizza contributed to this report.