WASHINGTON — The Senate on Wednesday confirmed Jeff Sessions as the next attorney general, following a bitter debate in the chamber that saw Republicans formally rebuke Sen. Elizabeth Warren, D-Massachusetts, for the manner in which she criticized her colleague from Alabama.

Sessions, a four-term U.S. senator, was the first senator to endorse Trump in February 2016, and his conservative, populist views have shaped many of the administration’s early policies, including on immigration.

The vote, 52-47 in favor of confirmation, ran largely down party lines. Sen. Susan Collins, R-Maine, voted in favor of the nomination and Sen. Angus King, I-Maine, voted against Sessions.

Republicans accused Democrats of seeking to undercut Trump by attempting to derail his Cabinet choices. “It’s no secret that our Democrat colleagues don’t like the new president and are doing what they can to undermine the new administration,” said Sen. Chuck Grassley, R-Iowa, the Judiciary Committee chairman.

He expressed disappointment in colleagues who, he said, suggested Sessions won’t be able to put aside his policy preferences and enforce the law. “This is especially troubling after he specifically committed to us during his confirmation hearing that, if he’s confirmed, he will follow the law, regardless of whether he supported the statute as a policy matter,” Grassley said.

Leading Democrats have argued that Trump’s criticisms of the federal courts over his immigration order makes the need for an attorney general who will be willing to disagree with the president even more urgent.

“What we’ve seen is a president who belittles judges when they don’t agree with him,” said Senate Minority Leader Chuck Schumer, D-New York. “What we’ve seen is a president who is willing to shake the roots of the Constitution and a fundamental premise — no religious test — that’s embodied in our Constitution within his first few weeks in office,” Schumer said. “We certainly need an attorney general who will stand up to that president. But [Sessions] is not, if you can say one thing about him, he’s not independent of Donald Trump.”

Sessions, 70, advanced out of the judiciary committee last week after a vote along party lines. The hearing took place after then-acting Attorney General, Sally Yates, an Obama administration holdover, had ordered the department’s lawyers not to defend Trump’s immigration order on grounds that she was not convinced it was lawful. Within hours, Trump fired her.

In his confirmation hearing last month, Sessions repeatedly vowed to put the law above his personal views. He said he would abide by the Supreme Court decision underpinning abortion rights and a court ruling legalizing same-sex marriage. He said he understood that the waterboarding of terrorism suspects to elicit information is “absolutely improper and illegal” and, though he voted against it, he would uphold a law banning the government’s bulk collection of phone records.

He also declared that he would recuse himself from Justice Department probe of Hillary Clinton’s email practices or her family’s charitable foundation, mindful that his previous comments “could place my objectivity in question.”

But he has repeatedly declined to say whether he would recuse himself from any investigation involving Trump associates and possible links to Russia’s interference in the presidential election, saying he would seek the recommendations of department ethics officials and “value them significantly” in making a decision.

Sessions’ confirmation leaves a vacancy that will be filled by Alabama Gov. Robert Bentley, a Republican. That term ends in 2018.

A measure of the hostility that has permeated the confirmation process for Trump’s Cabinet nominees was reflected in the rare censure of Warren after she read from a letter written by the late Coretta Scott King in opposition to Sessions’ nomination to the federal bench in 1986.

“The senator has impugned the motives and conduct of our colleague from Alabama,” said Majority Leader Mitch McConnell, R-Kentucky, of Warren, before the Senate voted along party lines to bar the Massachusetts senator from speaking during the remainder of the nomination debate.

Sessions, who came of age in the Deep South during the darkest days of the civil rights movement, has struggled to reconcile the charged racial politics of his region with the changing national discourse that has lifted longstanding legal barriers for minorities. His career has long been shadowed by charges that he is racially insensitive, which doomed his bid to become a federal judge.

His supporters have pointed to his prosecution as U.S. Attorney of two Ku Klux Klan members for killing a black youth, and his co-sponsoring of legislation to honor civil rights activist Rosa Parks with the Congressional Gold Medal. To underscore the point, Sen. Lindsey Graham, R-South Carolina, on Tuesday went to the floor and put on display an enlarged photograph of a “governmental award of excellence” given to Sessions in 2009 by the National Association for the Advancement of Colored People’s Alabama chapter — an award that he said Sessions “forgot to tell us about.” The plaque was engraved with the words “for the outstanding work you do.”

Said Graham: “His biggest crime is, I think, that he’s very conservative. That to me is not a disqualifier, any more than being liberal is a disqualifier.”

McConnell on Wednesday said, “It’s been tough to watch all this good man has been put through in recent weeks. This is a well-qualified colleague with a deep reverence for the law. He believes strongly in the equal application of it to everyone.”

But Sessions’ critics point to his record on voting rights, same-sex marriage, gender equality and immigration and say they fear he will work to restrict civil rights. They point to his prosecution of voting rights activists in Alabama in the 1980s that resulted in an acquittal for all three defendants, and which was the basis of King’s letter charging him with attempting to “intimidate and frighten elderly black voters.”

He has voted at least twice against comprehensive immigration reform, which was supported by members of his own party. They note he was one of just four senators in 2015 to oppose a Senate resolution affirming that the United States “must not bar individuals from entering into the United States based on their religion.”

Sen. Dianne Feinstein, D-California, the ranking member on the Judiciary Committee, said on the floor that her office had received 114,000 calls and emails regarding Sessions, with more than 98 percent opposed. She quoted from constituents who “deeply oppose this president and this nominee” and have hit the streets in protest. One doctor, she said, “marched because of the thousands of patients I’ve seen in the community, people of color, immigrants from all over the globe, who are terrified about the loss of their rights and the dramatic explosion of racially and culturally-focused hate crimes we’re reading about.”

She questioned how Sessions would handle the government’s investigation of Russian interference in the election, which could lead to the prosecution of individuals who helped hack the Democratic party in an effort to help Trump win.

“It obviously has the potential to create embarrassment for the president and his people, and to implicate people involved in the campaign,” she said. “Can [Sessions] be independent of the White House? I do not believe he can.”