Weeks after the Sept. 11, 2001, attacks, with bodies still being pulled from the smoldering rubble, New York’s mayor, Rudolph W. Giuliani, delivered an emotional address before a hushed United Nations.
He spoke with blunt force about the need for the world’s countries to unite in a global battle against terrorism. But he also sounded a powerful note of inclusion and unity, reminding the delegates — many of them Arab or Muslim — that New York was a city of immigrants, within a nation of immigrants.
“Like the victims of the World Trade Center attack, we’re of every race, we’re of every religion, we’re of every ethnicity, and our diversity has been our greatest source of strength,” he said. “It’s the thing that renews us and revives us in every generation — our openness to new people from all over the world.”
At the time, Mr. Giuliani’s political promise seemed limitless. But after a calamitous presidential run in 2008, his once-outsize profile shriveled.
Mr. Giuliani is now back on the national political stage, serving as one of Donald J. Trump’s most prominent advisers and most vocal defenders. Once an outspoken advocate of a bipartisan immigration overhaul, he is championing a candidate who has vowed to build an “impenetrable physical wall” on the country’s southern border and severely restrict immigration from Muslim countries.
He has assumed his new role with apparent relish, embracing some of the most controversial tactics of Mr. Trump’s campaign, including its penchant for unsubstantiated assertions: Last week, Mr. Giuliani said that Mr. Trump had abandoned his insistence that President Obama was born outside the United States, even though Mr. Trump has never done so publicly.
Mr. Giuliani has also questioned Hillary Clinton’s mental and physical health, buttressing his charges with debunked internet memes. “Go online and put down ‘Hillary Clinton illness,’ take a look at the videos for yourself,” he said last month.
But the Trump campaign has given Mr. Giuliani, a former federal prosecutor, the chance to mold a potential president, and to do battle with an old rival he deeply dislikes, one who he bitterly insists received special treatment from the F.B.I.
A Trump victory could open the door for Mr. Giuliani to return to public office, perhaps as head of the Department of Homeland Security or even Secretary of State.
But his ardent support for Mr. Trump could, alternatively, come at a cost to his legacy, as it has put Mr. Giuliani starkly at odds with other right-of-center Republican figures who have described the nominee as a dangerous threat to the nation and have refused to support him.
This is a source of deep concern to a large cadre of former Giuliani aides, people who recall him as the steely, compassionate leader of post-9/11 New York, and as the mayor who presided over a historic reduction in crime in the decade before — a period when he also denounced the most extreme elements of the Republican Party, advocated stricter gun control and signed a landmark domestic partnerships bill.
“That’s what makes it so painful to watch,” said Rick Wilson, an adviser to Mr. Giuliani’s 1997 re-election effort who is now advising a third-party candidate for president, Evan McMullin. “Trump is the kind of person that Rudy in a lot of ways would have laughed off the stage.”
In a telephone interview, Mr. Giuliani acknowledged that a large segment of people who have worked with him over the last three decades have recoiled from Mr. Trump’s candidacy. Among other things, his former aides have expressed concerns about Mr. Trump’s questioning of the impartiality of a judge because of his Mexican heritage, and belittling the Muslim parents of a slain Army officer.
“They don’t know him as well as I do,” Mr. Giuliani said, adding, “There’s not a racist bone in his body.”
The real Donald Trump, he said, “is a guy without these prejudices.”
Since Mr. Giuliani’s speech at the Republican convention in July, when he fulminated about the dangers of a Clinton presidency in tones that struck many as over the top, he has been a frequent presence by Mr. Trump’s side, trying to steady the Republican candidate’s wobbly campaign.
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.
The relationship between the two dates back decades, to when Mr. Trump was actively developing real estate in New York.
Mr. Trump was not a major donor to Mr. Giuliani’s campaigns, but in 1999, the mayor came under fire for a deal that allowed Mr. Trump to build a 72-story condominium tower on the East Side of Manhattan, far bigger than the zoning code had contemplated. That same year, Mr. Giuliani spoke at the funeral of Mr. Trump’s father, Fred, calling him “a giant.”
Mr. Trump lent his airplane to Mr. Giuliani at least twice in the immediate aftermath of Sept. 11. He let the mayor and Gov. George E. Pataki fly to Washington for President George W. Bush’s first address to Congress. There was a catch, though: The plane had been grounded at La Guardia Airport after the attacks. Mr. Trump asked Mr. Giuliani’s aides to help get the restriction lifted. They did.
Mr. Trump has sat in Mr. Giuliani’s box at Yankee Stadium, and each attended the other’s most recent wedding: Mr. Giuliani to Judith Nathan, Mr. Trump to Melania Knauss.
Now, they share a common adversary.
Mr. Giuliani had planned to run against Mrs. Clinton for the Senate in 2000, but dropped out of the race after a prostate cancer scare.
“He didn’t have a lot of use for either of the Clintons,” said Jerome Hauer, who was Mr. Giuliani’s emergency management director but later had a falling out with him. Mr. Hauer recalled having to persuade the mayor to let him give a briefing to President Bill Clinton in 1998.
“I think there’s a significant animus towards Hillary, almost a vendetta,” Mr. Hauer said.
Mr. Giuliani said he never considered running for president this year, despite a political climate that could have been more favorable to him. He also brushed aside speculation that he covets a cabinet position, saying his decision to support Mr. Trump was animated by his concern for the country’s security.
Nevertheless, watching Mr. Giuliani vouch for and cheer on the divisive Mr. Trump has been jarring for those who recall the former mayor’s denunciation of Patrick J. Buchanan’s anti-immigrant presidential campaign in 1996, and his leadership of a badly shaken city in September 2001, when he grimly warned that “the number of casualties will be more than any of us can bear, ultimately.”
It is those moments that many of Mr. Giuliani’s former aides hope he will be remembered for, not his full-throated support for Mr. Trump.
“Rudy is being called on to defend the indefensible,” John Avlon, the editor in chief of The Daily Beast and a former Giuliani speechwriter, said recently on CNN. “It doesn’t reflect his best self, but it should not define him in the totality of his career.”
Kitty Bennett contributed research.
Find out what you need to know about the 2016 presidential race today, and get politics news updates via Facebook, Twitter and the First Draft newsletter.
A version of this article appears in print on September 10, 2016, on page A1 of the New York edition with the headline: Giuliani Role Risks Legacy to Aid Trump.