WASHINGTON — Senator Jeff Sessions, President-elect Donald J. Trump’s nominee for attorney general, pledged on Tuesday to “say no” to Mr. Trump if he tries to go beyond the law, and he spoke out against torture, a ban on Muslim immigration and other ideas that had been floated by Mr. Trump.

Mr. Sessions, a deeply conservative Republican from Alabama who was an early Trump supporter, appears headed for confirmation after completing more than nine hours of testimony before the Senate Judiciary Committee. Mr. Sessions and his allies had girded for a coordinated attack on his civil rights record, but Democrats tempered their criticism and Republicans mounted a pre-emptive defense, describing him repeatedly as a man of integrity.

In his two decades on Capitol Hill, Mr. Sessions has questioned whether the Constitution guarantees citizenship to anyone born in the United States, has said courts have interpreted the separation of church and state too broadly and has declared same-sex marriage a threat to American culture. He also voted against reauthorizing the Violence Against Women Act.

Much of the hearing focused on Mr. Sessions’s long record as a prosecutor and a senator, but Mr. Trump proved a dominant figure in absentia for much of the debate as Democrats sought to question the president-elect by proxy. They asked whether Mr. Sessions supported Mr. Trump’s most controversial statements and questioned whether he had the independence to rein in the strong-willed Mr. Trump if he seeks to exceed his presidential authority.