NEW YORK—Michael Cohen, the president’s former personal lawyer, told a federal judge that Donald Trump had directed him during the 2016 campaign to buy the silence of two women who said they had affairs with Mr. Trump.

Mr. Cohen made the statement as he pleaded guilty Tuesday to eight criminal charges, including campaign-finance violations. He said he paid $130,000 to adult-film actress Stephanie Clifford, known professionally as Stormy Daniels, and coordinated a $150,000 payment by the publisher of the National Enquirer...