OTTAWA — The top political adviser to Prime Minister Justin Trudeau of Canada resigned on Monday, deepening a political crisis over allegations the government tried to interfere in a criminal court case.

In a statement announcing his departure, Gerald Butts, who has been a close friend of Mr. Trudeau’s since their university days, linked his leaving to the allegations that he, the prime minister and others improperly pressured Jody Wilson-Raybould, when she was the justice minister and attorney general, to quash the criminal prosecution of a major Canadian engineering and construction company.

Mr. Butts repeatedly denied in his resignation letter that any such action took place.

“Any accusation that I or the staff put pressure on the attorney general is simply not true,” Mr. Butts wrote. “But the fact is that this accusation exists. It cannot and should not take one moment away from the vital work the prime minister and his office is doing for all Canadians.”

He added: “It is in the best interests of the office and its important work for me to step away.”

His resignation came a week after Ms. Wilson-Raybould resigned from the Trudeau cabinet. In January, she had been moved from the post of justice minister to minister of veteran’s affairs, a switch widely seen as a demotion.