Sen. Jeff Sessions, President-elect Donald Trump’s choice for U.S. attorney general, forcefully rejected accusations that he has racist views, and departed from several of Mr. Trump’s campaign stances during a Senate confirmation hearing on Tuesday that drew tough questioning from his Democratic colleagues.

Mr. Sessions, a Republican from Alabama, said he doesn’t support a ban on Muslims entering the U.S., as Mr. Trump once proposed, and noted that the use of waterboarding is illegal under current law. Mr. Trump has advocated...