Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Roger Ailes resigned as chairman and CEO of Fox News Thursday, after days of speculation as to his future with the network after a sexual harassment lawsuit was filed against him by a former anchor, 21st Century Fox said.

Ailes also resigned Fox Business Network and Fox Television Stations, effective immediately, the company said. The announcement was made hours before Republican presidential nominee Donald Trump was set to speak on the final night of the Republican National Convention in Cleveland.

21st Century Fox co-chairman Rupert Murdoch will take over as chairman and acting CEO of the Fox News Channel and the Fox Business Network, the company said.

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

Roger Ailes, chairman and CEO of Fox News and Fox Television Stations. REUTERS

Ailes, 76, was accused of sexual harassment in a lawsuit filed earlier this month by former Fox News host Gretchen Carlson.

Ailes indicated in a letter to Murdoch released by a publicist that he would remain in an advisory role. "I am proud of our accomplishments and look forward to continuing to work with you as an adviser in building 21st Century Fox," Ailes stated in the letter.

Related: What Would Fox News Be Like Without Roger Ailes?

There was speculation this week that Fox News Channel was nearing a decision on Ailes’ future with the channel.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

21st Century Fox, the parent company of Fox News, launched a review after Carlson filed her lawsuit on July 6.

Roger Ailes' resignation letter to Rupert Murdoch, verified by @CNBC pic.twitter.com/nF3c8vluEP — Bradd Jaffy (@BraddJaffy) July 21, 2016

Carlson claimed in the suit that Ailes "sabotaged her career" after she rejected his sexual advances. The lawsuit quoted Ailes as saying "I think you and I should have had a sexual relationship a long time ago and then you'd be good and better and I'd be good and better," adding, "sometimes problems are easier to solve" that way.

Carlson was with Fox News for 11 years before last month. She was on network's popular morning show "Fox & Friends" but was removed and reassigned to an afternoon time slot in 2013. She most recently hosted "The Real Story With Gretchen Carlson.”

Carlson’s lawyers said Carlson’s contract was terminated on June 23. Ailes said her contract was simply not renewed, and the decision was due to poor ratings. He called the lawsuit "wholly without merit."

A year ago Murdoch put his sons Lachlan and James in charge of Fox News. A source with direct knowledge of the situation told NBC News that the brothers wanted Ailes out even back then.

James and Lachlan Murdoch said in a joint statement Thursday "We join our father in recognizing Roger’s remarkable contributions to our company."

Lachlan and James: “…We continue our commitment to maintaining a work environment based on trust and respect.” — 21st Century Fox (@21CF) July 21, 2016

In the letter to Murdoch, Ailes wrote he is proud of his accomplishments at Fox News.

"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. "Many of these talented journalists have deservedly become household names known for their intelligence and strength, whether reporting the news, fair and balanced, and offering exciting opinions on our opinion programs."

"Fox News has become Number 1 in all of cable because I consistently identified and promoted the most talented men and women in television, and they performed at the highest levels," Ailes stated in the letter.

The shakeup comes at an important time for Fox News, coming amid the National Republican Convention in Cleveland and ahead of the presidential election in which Trump will face Hillary Clinton, long a target of Republican ire.

Ailes was a prominent Republican media consultant who later ran CNBC before Murdoch asked him to create a cable news network to compete with CNN at the same time MSNBC was starting. Ailes' slogans, "fair and balanced" and "we report, you decide," appealed to an audience that believed mainstream outlets didn't live up to those promises.

"He was ahead of his time in recognizing that dividing, not uniting, an audience would be the key to commercial success in the 21st Century cable news business," Matt Sienkiewicz, communications professor at Boston College, told The Associated Press. Ailes blew apart the notion that public affairs programming should target a broad audience with civil debates, he said.

By 2002 Ailes lifted Fox into first place among cable news networks, where it has remained for over a decade.

"It is always difficult to create a channel or a publication from the ground up and against seemingly entrenched monopolies. To lead a flourishing news channel, and to build Fox Business, Roger has defied the odds,” Murdoch said in the statement. “His grasp of policy and his ability to make profoundly important issues accessible to a broader audience stand in stark contrast to the self-serving elitism that characterizes far too much of the media."

Since Carlson filed her lawsuit, several other women have alleged sexual harassment by Ailes, detailed in an article in New York Magazine.The alleged incidents occurred decades ago, before the launch of Fox News. Ailes' personal attorney has denied the claims in the New York Magazine article.

Several female Fox anchors, including Maria Bartiromo, Jeanine Pirro and Greta Van Susteren, have stepped forward to defend Ailes.

Bartiromo was quoted in Variety as saying Ailes has been nothing but professional. Pirro and Van Susteren told The New York Times they never witnessed the behavior described in Carlson's suit.

Carlson’s legal team said in a statement after the resignation Thursday that "Gretchen Carlson's extraordinary courage has caused a seismic shift in the media world."

"We hope that all businesses now understand that women will no longer tolerate sexual harassment and reputable companies will no longer shield those who abuse women," the statement said. "We thank all the brave women who spoke out about this issue."