By Jessica Toonkel and Lisa Richwine

NEW YORK/LOS ANGELES (Reuters) - Roger Ailes on Thursday resigned as chairman and chief executive of Fox News Channel following allegations of sexual harassment, an abrupt end to his 20-year rein over America's most lucrative and powerful cable news channel for conservatives.

Rupert Murdoch, 85, the executive chairman of Twenty-First Century Fox Inc, the parent of Fox News, will assume the role of CEO Fox News and Fox Business Network on an interim basis, the company said on Thursday.

Ailes, who will serve as an informal adviser to Rupert Murdoch and no longer have an official role at the company, will receive a severance package of about $40 million, according to a source familiar with the situation, who asked to remain anonymous.

In his resignation letter to Murdoch, Ailes did not indicate he had done anything wrong.

"I take particular pride in the role that I have played advancing the careers of the many women I have promoted to executive and on-air positions," Ailes wrote in the letter, which his lawyer Susan Estrich provided to Reuters.

However, he added: "I will not allow my presence to become a distraction from the work that must be done every day to ensure that Fox News and Fox Business continue to lead our industry."

The resignation marks a swift downfall for Ailes, the 76-year-old media executive who advised several U.S. Republican presidents, including George H.W. Bush, and turned Fox News into the most-watched U.S. cable news channel.

His departure comes on the final and biggest night of the Republican National Convention, where Donald Trump will formally accept the Republican presidential nomination.

Trump tweeted on Thursday, “Roger Ailes just called. He is a great guy & assures me that 'Trump' will be treated fairly on @FoxNews. His word is always good!”

Former Fox News anchor Gretchen Carlson sued Ailes earlier this month, claiming sexual harassment. Ailes has denied the charges. Fox hired a law firm to conduct an internal investigation.

New York magazine followed up with reports of other women who said they had been harassed by Ailes. On Tuesday, the magazine said that popular Fox News anchor Megyn Kelly had told investigators hired by Fox that Ailes "made unwanted sexual advances toward her" about 10 years ago.

Ailes, who founded the cable channel in 1996, did not sexually harass Kelly, according to a statement attributed to his lawyer in the New York Times on Tuesday.

The resignation comes as Fox News, known for a lineup of politically conservative commentators including best-selling author Bill O'Reilly, is drawing record viewership. The network is the most-watched channel in all of basic cable television this year with an average of 2.2 million prime-time viewers, according to Nielsen data through June.

CHALLENGES AHEAD

Whoever replaces Ailes faces the twin challenges of retaining Fox News' established on-air stars such as O'Reilly and Kelly, while making the network attractive to younger viewers, a demographic it has consistently missed.

O'Reilly and Kelly's contracts are up in 2017, and stars including Greta Van Susteren and Sean Hannity all have clauses in their contracts that allow them to leave the network if Ailes departs, according to media reports.

New management will also have to win over the many Ailes loyalists left in the ranks.

"Roger Ailes is the best boss I have ever had. I admire him professionally," Fox News anchor Chris Wallace said in an email. "And I love him personally. I am heartbroken he is gone."

Murdoch, who built his father's Australian newspaper business into one of the world's most powerful news and entertainment conglomerates, has always been fiercely loyal to Ailes and cut his vacation short in the French Riviera with his wife Jerry Hall to handle the resignation.

The media mogul may be better positioned than anyone to keep morale up and persuade talent to stay, said Brian Wieser, an analyst at Pivotal Research Group: “Fox News was as much his baby as it was Ailes’ baby. I think it’s a great short-term solution."

Nevertheless, Fox would be wise to work quickly to find a new CEO, said Merrill Brown, a former media executive who helped launch MSNBC. “It is a good choice if its length is measured in weeks."

Ailes' long experience as both a television producer and a Republican strategist helped him to formulate a winning strategy: hire charismatic talent to appeal to a conservative audience.

“Roger Ailes has made a remarkable contribution to our company and our country," Murdoch said in a statement. "Roger shared my vision of a great and independent television organization and executed it brilliantly over 20 great years."

Critics said Ailes pushed a Republican agenda under the oft-repeated slogan "Fair and Balanced." His fans said he smartly recognized that conservative TV viewers were not seeing their viewpoints reflected on Time Warner Inc's CNN or major broadcast networks.

Fox News Channel went on the air in 1996, just before Bill Clinton was elected to a second term as president, with Ailes as founding CEO.

While Ailes' departure may not come at an ideal time for Fox News, the momentum of record ratings amid the most sensational U.S. presidential election in decades may give the cable network some breathing room to recover, media buyers and Wall Street analysts have told Reuters.

And some of them say this could be an opportunity for Fox News, whose median age of viewers is over 65, to focus on getting younger fans.