In the rarefied world of New York moguls, Rupert Murdoch never thought much of Donald J. Trump.

Mr. Trump’s divorces and marriages sold newspapers, but beyond that, Mr. Murdoch had no time for his bombastic business style and ostentatious demeanor. “Phony” was how Mr. Murdoch often described him to friends.There was the time Mr. Trump screamed that he would sue for libel after Mr. Murdoch’s New York Post reported that the exclusive Maidstone golf club in East Hampton planned to deny Mr. Trump a membership.

Then there was the awkward aftermath of Mr. Murdoch’s own high-profile divorce from Wendi Deng Murdoch, when Mr. Trump’s daughter Ivanka, unlike many New York society figures, remained loyal to Ms. Deng Murdoch, a close friend.

Donald Trump greeted supporters after taping an interview with Anderson Cooper in Midtown Manhattan on Wednesday.

Donald J. Trump in Ames, Iowa, on Saturday. Mr. Trump has lately focused his attention on veterans’ issues and in particular has been critical of Senator John McCain, who was a prisoner of war for five years in Vietnam.

Donald Trump works and often sleeps in the penthouse on the 66th floor of Trump Tower in Midtown Manhattan, when he's not staying at one of his other homes.

Senator John McCain presented John R. Pedevillano, 93, a World War II Air Force bombardier, with the Presidential Unit Citation with one Oak Leaf Cluster at a ceremony on Capitol Hill this month.

Who Is Running for President?JAN. 30, 2015

Now, as Mr. Trump holds on to a first-place position in the polls while being roundly denounced across the political spectrum for harsh statements about Mexican immigrants and for belittling Senator John McCain’s war record, he has already lost the man who controls many of the nation’s most important media organizations.

Rupert Murdoch, with his son Lachlan this month, is no fan of Mr. Trump’s bombastic business style and demeanor. Credit Scott Olson/Getty Images

“When is Donald Trump going to stop embarrassing his friends, let alone the whole country?” Mr. Murdoch wrote on Twitter on Saturday after Mr. Trump mocked Mr. McCain for having been captured as a pilot during the Vietnam War.

On Sunday, The Wall Street Journal, the crown jewel of Mr. Murdoch’s print company, News Corporation, published a scathing editorial calling Mr. Trump a “catastrophe.” And The Post’s front page screamed, “DON VOYAGE,” under a headline declaring, “Trump is toast.”

Mr. Trump responded by trashing The Journal on Twitter. “Look how small the pages have become,” he wrote. “Looks like a tabloid.”

Recognizing that winning over the notoriously headstrong Mr. Murdoch appears unlikely, Mr. Trump has set his sights instead on wooing perhaps the only media executive who wields as much firepower among Republicans: Roger E. Ailes, the chairman and chief executive of Fox News.

As the creator of the highest-rated cable news channel in the country (even surpassing ESPN in total viewers on some nights) and one of the most profitable assets in Mr. Murdoch’s film and television company, 21st Century Fox, Mr. Ailes has been given the freedom to operate largely outside the purview of Mr. Murdoch.

Mr. Trump and Mr. Ailes, whom Mr. Trump has called “one of the great geniuses in television history,” had a private lunch last month in New York. (A Fox News spokeswoman, Irena Briganti, said they had known each other for about 25 years and had a cordial relationship.) But Mr. Trump has not reached out to arrange a meeting with Mr. Murdoch, as a number of other Republican candidates have.

Fox News has by no means given Mr. Trump a pass for his remarks about Mr. McCain. On Monday, the host Bill O’Reilly chided Mr. Trump. “He was on a bombing mission, he was shot down, he was tortured,” Mr. O’Reilly said. “Come on, Donald, you know that the way that came off wasn’t correct!”

To which Mr. Trump replied with the closest thing yet to an apology: “Certainly if there was a misunderstanding, I would totally take that back.”

CNN and MSNBC have also devoted hours to Mr. Trump, whose histrionics have been a ratings bonanza. But his treatment by Fox News is much more crucial because of the influence the channel wields among the Republican Party’s base. And Fox News, as the host of the first primary debate on Aug. 6, has set the criterion that the debate will include the top 10 candidates as determined by national polls; Mr. Trump currently tops many polls.

Mr. Ailes, who recently renewed his multiyear contract, enjoys his editorial independence and his position as cable news contrarian. And in Fox News’s serious handling of Mr. Trump so far, longtime associates of Mr. Ailes discern a larger plan.

If the Trump balloon ultimately bursts, they suggested, it could buy time for other Republican contenders to hone their messages and become more seasoned campaigners. Either way, Mr. Ailes benefits with ratings in the meantime.

Ms. Briganti, the Fox News spokeswoman, called any implication that the channel’s coverage of Mr. Trump was a ploy to help the eventual Republican nominee “absolute nonsense, 100 percent untrue and said by someone who clearly doesn’t know Roger.”

For Mr. Murdoch, his misgivings about Mr. Trump long predate the current dust-up — though a core policy disagreement over immigration, friends say, prompted Mr. Murdoch to speak out.

Mr. Murdoch, an Australian native, has long pushed for an overhaul of the United States’ immigration system, including a path to citizenship for the 11 million people already in the country illegally.

Mr. Trump, in his presidential kickoff, warned that Mexican immigrants were bringing drugs into the country and called them “rapists” and criminals — a statement that many Republicans fear will deeply damage the party with Hispanic voters.

“Mexican immigrants, as with all immigrants, have much lower crime rates than native born,” Mr. Murdoch wrote on Twitter on July 12. “Trump wrong.”

But Mr. Trump’s remarks struck a populist chord with many conservatives, for whom opposing a path to citizenship is a key rallying point.

Ann Coulter, the conservative commentator, whose new book, “¡Adios, America!” addresses the nation’s immigration system, said, “Immigration is the new litmus test on the right.”

“Right now, it’s Trump! Trump! Trump! because he’s the only one talking about immigration,” she said in an email.

But Mr. Murdoch’s history with Mr. Trump extends well beyond immigration.

For years, the name Trump in a headline meant eyeballs and newsstand sales for Mr. Murdoch’s beloved New York Post, which broke its own record for front-page stories on a single topic in the 1990s with its coverage of Mr. Trump’s affair with Marla Maples and his split with Ivana Trump.

Mr. Trump long benefited from the publicity The Post provided him — even in headlines (“Best Sex I Ever Had,” quoting Ms. Maples) that might embarrass a private person — as he transitioned from flashy real estate developer to even flashier reality television star.

The relatively low-key Mr. Murdoch, who would prefer an ink-stained newsroom to a gold-plated Trump penthouse, was turned off by Mr. Trump’s glitziness and braggadocio, friends said.

Mr. Trump defended Mr. Murdoch during the phone hacking scandal at his British newspapers: When a select parliamentary committee declared Mr. Murdoch “unfit” to run them, Mr. Trump said, “They should be so lucky to be as unfit as him,” according to The Australian — another Murdoch paper.

Mr. Murdoch crossed paths with Mr. Trump more frequently when his now ex-wife Ms. Deng Murdoch became close friends with Mr. Trump’s daughter Ivanka. The Murdochs and Ms. Trump and her husband, Jared Kushner, the publisher of The New York Observer, double-dated and vacationed on Mr. Murdoch’s 184-foot yacht. The Murdochs’ 2013 divorce put an end to those excursions, though Mr. Murdoch remains friendly with Mr. Kushner.

But aside from the stray threat of a lawsuit, tensions between Mr. Trump and Mr. Murdoch did not escalate into public warfare until this year.

“Wow, I have always liked the @nypost but they have really lied when they covered me in Iowa,” Mr. Trump wrote on Twitter in January. “Packed house, standing O, best speech! Sad.”