Fox News is losing its mojo.

After parting ways with the most-watched personalities in cable news and firing its founder over allegations of sexual harassment, the conservative-oriented Fox dropped to third place last week in prime time among the viewers that advertisers court, a spot it hasn’t occupied for almost 17 years. Meanwhile, left-leaning MSNBC soared to No. 1 for a second straight week, helped by news on probes into the Trump campaign’s alleged ties to Russia.

The reversal marks a big shakeup in TV news and could alter the fortunes of all three news networks — Fox, MSNBC and CNN — if it lasts. Audience ratings drive the subscriber fees and advertising rates that all three outlets charge, and being No. 1 for 15 years has made Fox News the most profitable channel at parent 21st Century Fox Inc. A long exile in third place would matter.

“That’s when investors will see it,” said Brett Harriss, an analyst at Gabelli & Co. who recommends buying shares of 21st Century Fox. Until then, “it’s kind of wait and see.”

Fox shares have dropped 4.4 percent this year, compared with a 6 percent gain for the S&P 500 Media Index.

On the surface, MSNBC’s rise can be explained by the fact that it has become a rallying point for those opposed to President Trump, said Andrew Tyndall, whose Tyndall Report monitors TV news. As troubles mounted for the administration last week, MSNBC’s audience swelled.

“These type of breaking news events are going to attract news viewers who are interested in learning more negative things about Donald Trump than positive things,” Tyndall said.

To be fair, Fox isn’t losing viewers — for now it’s just bragging rights to No. 1 that are in play. All three networks have benefited from heightened interest in the Trump administration’s turmoil, showing growth in total viewers and the 25-to-54-year-olds that advertisers target when they buy spots in newscasts.

So far this year, Fox News is still first in viewers of all ages for the full day, with its audience up 23 percent, according to Brian Wieser, an analyst at Pivotal Research Group. Comcast Corp.’s MSNBC, fueled by the growing appeal of commentators Rachel Maddow and Lawrence O’Donnell, has seen its followers more than double. CNN, part of Time Warner Inc., is up 54 percent.

But last week, MSNBC climbed to first in total weekday viewers with 2.44 million in prime time, compared with Fox’s 2.41 million, and continued to lead in the younger demographic. That was Fox’s worst finish since 2000, TVNewser reported Monday. CNN was second in the key age group and third overall.

Including the weekend, Fox News still came out on top last week, a Fox News spokesperson said. And the company won first place Monday night, when all three networks were covering the terrorist attack in Manchester.

Cable news channels with political slants often get better ratings during the presidencies of the opposing side. Fox News came to prominence during the impeachment of President Bill Clinton and got a second-wind during the Obama administration, Tyndall said.

MSNBC spent years in third place fine-tuning its identity as a liberal commentator on breaking news. Now daily developments in Washington are drawing larger numbers of more liberal-minded viewers to MSNBC, just as Fox News used Democratic administrations as a magnet for conservative audiences.

“They’re reaping the benefits of all the work they’ve done in the wilderness all these years,” Tyndall said. “It’s payoff for work already done, more than work being done right now.”

Fox’s recent drop to third can also be explained by the turmoil in its prime-time lineup and management. In the past year, the network has lost three of its biggest stars — Bill O’Reilly, Megyn Kelly and Greta Van Susteren. O’Reilly, the most-watched personality on cable news, was fired for alleged sexual harassment. Kelly jumped to NBC while Van Susteren is now at MSNBC.

Behind the scenes, Fox News also lost founder and Chairman Roger Ailes, the ideological patriarch of the network and architect of its talent lineup, along with his deputy Bill Shine. Ailes was driven from the job over charges of sexual harassment, allegations that are forcing Fox to fight numerous lawsuits by aggrieved former female employees. He died last week from complications after a fall. Shine resigned over the network’s handling of the women’s complaints.

“That’s an awful lot of change in a given year,” Tyndall said.

Fox has rebuilt its prime-time lineup to replace the lost personalities, with Tucker Carlson replacing O’Reilly at 8 p.m., the round-table talkshow “The Five” in Kelly’s old spot at 9 p.m. and longtime conservative firebrand Sean Hannity staying at 10 p.m.

Last week, 21st Century Fox founder Rupert Murdoch, who has been leading Fox News in the wake of Ailes’s exit, announced an investment of millions for a new newsroom and the hiring additional staff to expand Fox News’ capabilities on various platforms including digital.

In recent weeks much of Fox’s prime-time coverage has downplayed the controversies engulfing the Trump administration or blamed the Republican president’s troubles on a hostile media. On Monday, the network pre-empted “The Five” at 9 p.m. with an hour newscast hosted by Shepard Smith focusing on the terrorist attack in Manchester, followed by a live telecast of Hannity, whose show is usually taped. Smith then returned to host another hour of news at 11 p.m. The change paid off, putting Fox back on top in prime time.

“Fox News has a problem,” O’Reilly said last week on a radio show hosted by Glenn Beck, himself a former Fox commentator. “Whenever you lose key personnel in any competitive industry — sports, media — you better have a plan. And it doesn’t look like FNC has a plan.”