He accompanied Mr. Trump to Mexico on Aug. 31, and then introduced him before his immigration speech the same night in Phoenix, even donning a white “Make Mexico Great Again Also” hat for the occasion. Mr. Giuliani has played a significant role behind the scenes, too, urging Mr. Trump to tone down his remarks and rethink his immigration plan. He also took control of a private campaign round-table discussion of national security recently, in which he addressed the room as often as Mr. Trump did, according to someone in attendance.

Former Giuliani aides discern other imprints on the Trump campaign: Mr. Trump’s policy addresses about school reform and his recent outreach to black voters in Detroit, they said, contained echoes of Mr. Giuliani’s mayoral re-election campaign in 1997, when he argued with black New Yorkers that Democrats had let them down.

Mr. Giuliani still has his defenders.

“Rudy Giuliani presided over the single greatest transformation of a major American city in our history,” said Anthony V. Carbonetti, a longtime adviser. “It sickens me to hear people diminish that simply because they disagree with his politics.”

Mr. Giuliani said that he did not share all of Mr. Trump’s views, but that on the issues that mattered most, the economy and foreign policy, they were in sync. He said he believed that Mr. Trump had made adjustments in his approach, including on immigration.

On paper, at least, the two men have much in common. Both are relatively socially liberal and twice-divorced products of neighborhoods outside Manhattan, where they eventually gained fame. Both are pugnacious, with hearty appetites for conflict and for attention from a news media they often condemn as biased.

But there are significant differences. Mr. Giuliani is a well-read student of history who absorbs himself in the details of policy debates. Mr. Trump skims briefing books and prefers to get his information from cable news.

Mr. Giuliani waited until the New York primary to declare his support for Mr. Trump, then did so cautiously, saying he was troubled by some of the candidate’s more personal attacks on his rivals. But once Mr. Trump won the nomination, Mr. Giuliani’s tentative embrace became a bear hug.