TRENTON — It was only the second time U.S. Sen. Jeffrey Chiesa voted on a bill, but by joining all the Democrats and 13 Republicans to pass a sweeping overhaul of the country’s immigration laws today, the senator from New Jersey likely cemented his legacy in Congress.

Formerly the state attorney general, Chiesa (R-N.J.) was appointed by Gov. Chris Christie earlier this month to fill the late Frank Lautenberg’s seat until a special election in October.

Before he leaves, the Senate has no other bills in the pipeline as ambitious as the immigration overhaul, which allows the nation’s estimated 11 million undocumented immigrants to seek citizenship after 13 years, doubles the number of Border Patrol agents to roughly 40,000, calls for building 700 miles of new fencing along the southern border, and broadens the number and types of visas for legal immigrants, among other measures.

“I will vote for this immigration bill because I believe it is the right thing to do,” Chiesa said in a statement today. “As a former federal prosecutor and attorney general for the state of New Jersey, I have looked carefully at this debate through the lens of public safety and law enforcement. ... This bill strengthens border security.”

Of the 11 million estimated undocumented immigrants, around 400,000 live in New Jersey, Chiesa told The Star-Ledger last week. Still, his vote today put him at odds with the two candidates seeking the GOP nomination for the Senate seat, former Bogota mayor Steve Lonegan and Franklin Township physician Alieta Eck.

“Every part of this bill is poorly thought out,” Lonegan said, describing it as a free pass for undocumented immigrants that doesn’t go far enough strengthening border security.

Eck said the bill needed tighter controls on illegal crossings through the Mexican border.

“No modern state can have a border as porous as ours and guarantee national security,” she said in a statement.

Chiesa voted for amendments that would have made the bill tougher on border security, but when they didn’t pass, he still voted for the final bill.

“This will definitely be the biggest thing he does as U.S. senator,” said Patrick Murray, a pollster at Monmouth University. On the split between Chiesa and the GOP candidates, Murray added: “It’s a function of Chiesa being in law enforcement for his entire career. Republicans who work in prosecutors’ offices believe that some type of compromise in this vein is necessary, that this is the best possible approach given all the options.”

Chiesa’s vote put him on the same side as U.S. Sen. Robert Menendez (D-N.J.), one of the bill’s lead architects and a member of the “Gang of Eight” that drummed up support for months until its passage in the Senate.

Menendez, the chairman of the Senate Foreign Relations Committee, whose family hails from Cuba, said in a floor speech before the vote that the issue was deeply personal.

“I come here thinking of what this bill will mean for families, and come here thinking of my family — of my mother who came from Cuba, worked hard, and made it possible for me to stand here today,” he said.

Republican leaders in the House of Representatives, however, have said they want to take a different approach that tackles each immigration issue individually instead of grouped together as in the Senate bill.

“Do the right thing for America and for your party,” Menendez urged House members. “Find common ground. Lean away from the extremes. Opt for reason and govern with us.”