Sen. Patrick Leahy of Vermont will take a central role in shaping immigration reform.

WASHINGTON — As the U.S. Senate plowed through gun amendment after gun amendment one night last week, Sen. Patrick J. Leahy, the Judiciary Committee chairman, sat at his desk on the Senate floor in increasing agitation as a potentially momentous personal achievement collapsed in a partisan morass.

“The committee held three hearings and four lengthy markups starting in January and concluding in March,” Leahy, Vermont’s senior senator and the newly anointed president pro tempore, said in bitter frustration. “No good deed goes unpunished.”

It was the opening act of perhaps Leahy’s biggest moment after 38 years in the Senate, and it was crumbling around him. Act Two began Friday, with Leahy’s Judiciary Committee plunging into the first formal hearing since a sweeping overhaul of the nation’s immigration laws was introduced in the Senate.

He can only hope this one goes better.

Over nearly four decades, Leahy has compiled an extensive resume of workmanlike accomplishments, lauded but little known beyond the immediate beneficiaries: the Patrick Leahy War Victims Fund, the Leahy Law that controls U.S. military assistance to governments with questionable human rights records, patent law, privacy protections, organic food labeling and agricultural conservation programs.

They are important achievements, he says, but not the sort carved into marble in the Capitol.

Then came 2013 and two huge tasks, guiding the first major gun control legislation since 1994, then managing the broadest overhaul of U.S. immigration law since Ronald Reagan was president.

Leahy has also hinted that a Supreme Court fight could come soon — a hint worth noting since he knew months before the public that the last two court vacancies were looming.

It is a moment he asked for when he stunned colleagues in December by turning down the chairmanship of the powerful but troubled Senate Appropriations Committee to stay with Judiciary. And even with this week’s turn of events, aides say he is still relishing it.

At a private Oval Office meeting with President Barack Obama on Feb. 4, Leahy ticked off the tasks that lay before him in the opening months of Obama’s second term: the Violence Against Women Act, gun safety legislation, immigration and a possible Supreme Court confirmation fight.

“Anything else you want to throw my way?” Leahy said he asked the president. “He said: ‘I know you get bored. I don’t want you to get bored.”’

“Thanks a bunch,” Leahy replied.

Quirks and twists are part of his personal story and are informing the tasks at hand. Leahy had a small speaking part in “The Dark Knight Rises,” the Batman blockbuster that was opening at a midnight screening in Aurora, Colo., when a gunman opened fire last year, killing 12 and injuring dozens.

The next morning, Leahy called some of the electricians and carpenters he had befriended on the set to commiserate over the tragic opening.

The school shootings in Newtown, Conn., only furthered the resolve for a senator who once vehemently opposed background checks as meaningless symbolism.

Prickly and quick-tempered, Leahy has jealously guarded the jurisdiction of his committee, but he has also tolerated lengthy bipartisan negotiations on immigration.

That tolerance, however, has come with a warning: “A day will come when we will vote on it in the Judiciary Committee, we will vote up or down and I will not have something come out of there that I will not vote for,” he said. “I will have the final say.”

John D. Podesta, a former senior Leahy aide who went on to be White House chief of staff under President Bill Clinton, said Leahy did not fit neatly in with epic Democratic figures like Edward M. Kennedy and Robert Byrd, who saw their lengthy tenures in the Senate as opportunities to shape society through “massive social legislation” and permanent stamps on the institution itself.

The small-state product of immigrant grandparents and the son of a printer, Leahy has been more skeptical of governmental power, focusing on privacy protections and criminal justice.

“I think this moment, particularly immigration reform, will figure large in how he ultimately is perceived,” Podesta said.

With his ascension to the mainly ceremonial position of Senate president pro tempore, the most senior senator of the majority party, Leahy has something he had never sought, a position in leadership. He is also third in succession to the presidency.

His interests are not typical of Washington. His office in the Senate’s stately Russell Office Building — once belonging to the conservative legend Barry Goldwater — is a glimpse at history through his one good eye, peeking through his ever-present camera.

A series of photos he shot depicts a closed-door confrontation between Obama and Joseph I. Lieberman, then a senator from Connecticut, during negotiations on the health care law. The president listens, leans back, folds his arms. Sen. Richard J. Durbin, D-Ill., rubs his eyes. Vice President Joe Biden rolls his.

The “conscience photo” above his desk is of an elderly refugee he photographed in 1982 in El Salvador, whose eyes follow him while he is working. On his bookcase, the complete, annotated lyrics of the Grateful Dead are wedged between a history of the Federal Bureau of Investigation and the biography of former Sen. David Pryor of Arkansas.

Another pursuit open to a one-eyed senator is marksmanship, and Leahy has been an avid shooter all his life, from his days as a marksman on his college team to more recent forays into the backyard to plunk chunks of ice.

Ed Pagano, a former Leahy chief of staff and now Obama’s chief Senate lobbyist, recalled firing a .50-caliber handgun on the Leahy farm in Vermont, calling it “Dirty Harry time.”

Dirty Harry was an unlikely skipper for gun control legislation. And in December that was not expected to be his job.

With the death of Sen. Daniel K. Inouye, D-Hawaii, that month, Sen. Harry Reid of Nevada, the majority leader, tried to seize an opportunity to reshuffle the power structure beneath him. Inouye died on a Monday evening, Dec. 17, with a showdown over huge tax increases and automatic spending cuts just days away.

At 8:30 a.m. the next day, Leahy’s staff was presented with Reid’s new lineup: Leahy would take Inouye’s position as Appropriations chief, Sen. Dianne Feinstein of California would take over Judiciary, and Sen. Barbara A. Mikulski of Maryland would take Feinstein’s chairmanship of the Intelligence Committee. The slate would be presented at the Senate Democrats’ lunch that day.

Leahy, feeling jammed, said he could not agree that quickly and begged for more time. He was told he had until Thursday. Two agonizing days later, he scrambled Reid’s plans and opted to stay.

The next two months had “a lot to do with” that decision, Leahy said.

“I’m excited each time I walk into the Judiciary Committee,” he said. “I want to be excited about going to work. I know that might sound silly.”