The Senate has confirmed President Trump's nominee Jeff Sessions to be the next attorney general, bringing an end to a bitter confirmation fight that has dredged up past accusations of racism against the Alabama senator.

The vote was largely along party lines, 52-47, with only centrist Democratic Sen. Joe Manchin of West Virginia voting yes. Sessions himself voted "present" on his own nomination.

During the past month, Democrats have brought up the past allegations of racism against Sessions, which sank his nomination by President Ronald Reagan three decades ago to be a federal judge. The then-U.S. attorney admitted he had made insensitive remarks and called some top civil rights groups such as the ACLU "un-American."

In his confirmation hearing, Sessions pushed back, saying that his comments were taken out of context.

"I did not harbor the kind of animosities and race-based discrimination ideas I was accused of. I did not," Sessions told the Senate Judiciary Committee, though he admitted that, "I didn't know how to respond and didn't respond very well" during his first failed confirmation.

However, his nomination had drawn some strong and unprecedented rebukes from his colleagues across the aisle.

Sen. Elizabeth Warren, D-Mass., was formally silenced by the Senate after she read a letter Coretta Scott King, the widow of the Rev. Martin Luther King Jr., wrote in 1986 objecting to Sessions' ultimately unsuccessful nomination to the federal bench. The unusual rebuke came because of a rule barring senators from using "any form of words impute to another Senator."

Last month, Sen. Cory Booker, D-N.J., became the first sitting senator ever to testify against a fellow senator's confirmation, arguing he has concerns regarding Sessions' commitment to defending minorities, the LGBT community and voting rights. Rep. John Lewis, D-Ga., the legendary civil rights leader with whom Trump got into a spat just before his inauguration, also testified against Sessions.

Sessions is the former Alabama attorney general and was first elected to the Senate in 1996. He is one of the most conservative senators in the GOP conference and has been an outspoken opponent of illegal immigration.

It was that shared worldview that led Sessions to become the first senator to endorse the billionaire real estate mogul back in February 2016. One of Sessions' former top aides, Stephen Miller, left his office to work for Trump's campaign and is now a senior White House adviser for policy who has had a heavy hand in crafting many recent executive orders.

With Sessions' confirmation, Trump will have one of his closest allies at the Justice Department at a critical time when the president needs help defending his controversial immigration and travel ban in the courts.

Last month Trump fired Acting Attorney General Sally Yates, a holdover from the Obama administration, after she announced she would not defend his executive order on immigration, replacing her with Dana Boente, the top federal prosecutor in suburban Virginia. Now, Sessions will assume the role of overseeing the defense of the executive order that halts people from seven Muslim-majority countries from coming into the U.S. and stops any resettlement of Syrian refugees.

Copyright 2017 NPR. To see more, visit http://www.npr.org/.