WASHINGTON—President Trump denied playing a part in illegal hush-money payments to two women during the 2016 campaign and berated his former lawyer for swearing in court a day earlier that he had, leaving the White House and both political parties Wednesday to sort through the fallout less than three months before midterm elections.

Mr. Trump and administration officials sought to discredit Michael Cohen, who said Tuesday as part of a guilty plea in federal court that the president directed him to buy the silence of the women...