Megyn Kelly wanted out of Fox News.

On Tuesday she stunned the television news world by defecting from Fox, her TV home for the past decade, and joining NBC News.

Later this year Kelly will start hosting a daytime news program on weekdays and a prime time program on Sundays, both on the NBC network.

Kelly will only be on Fox for a few more days. She will sign off her 9 p.m. show, "The Kelly File," on Friday night.

The move will be perceived in the industry as a coup for NBC and a blow to Fox. In the past couple years, Kelly has become one of the biggest stars on television as she defied expectations and tangled with Donald Trump.

Bolstered by Bill O'Reilly's 8 p.m. show, Kelly at 9 p.m. had the second-most watched news program on all of cable news.

Kelly's contract was coming due in July, which meant her future was the topic of constant speculation in the TV industry.

Rupert Murdoch and his sons James and Lachlan, who oversee Fox News and the rest of 21st Century Fox, worked hard to convince Kelly to stay within the company, offering her several different options.

Kelly and her representatives held talks with CNN and ABC, among other potential outlets, before deciding on NBC.

The announcement, initially reported by The New York Times and confirmed minutes later, appeared to catch Fox somewhat off guard.

Fox made no immediate announcement about a new prime time host.

Sources with knowledge of the matter said that Fox News had offered Kelly an annual salary of more than $20 million to stay at the network, matching the salary of O'Reilly, her colleague and rival.

Kelly weighed her options and talked with her family throughout the month of December, according to one of the people she deliberated with. She informed Lachlan Murdoch of her decision on Tuesday morning. "They had a lovely conversation," the source said.

During the months of negotiations, television industry executives said other networks were highly unlikely to match Fox's financial offer to Kelly.

But "money wasn't the driving factor" in Kelly's decision, her spokeswoman Leslee Dart said.

Dart declined to comment on any of the specific deal terms.

Kelly told friends that one of her top priorities was a family-friendly work schedule. Kelly has three young children and wasn't getting home on weekdays until well after their bedtime.

A daytime program on NBC will give Kelly a lot more flexibility.

"Megyn is an exceptional journalist and news anchor, who has had an extraordinary career," NBCUniversal News Group chairman Andy Lack said in an email to staff. "She's demonstrated tremendous skill and poise, and we're lucky to have her."

In a Facebook post, Kelly wrote that she was leaving Fox News "incredibly enriched" by her twelve years at the network.

"While I will greatly miss my colleagues at Fox, I am delighted to be joining the NBC News family and taking on a new challenge," she wrote. "I remain deeply grateful to Fox News, to Rupert, Lachlan and James Murdoch, and especially to all of the FNC viewers, who have taught me so much about what really matters. More to come soon."

Lack's internal memo said Kelly would start hosting "later this year." He did not list a specific start date. In addition to her own programs, Kelly will contribute to NBC's breaking news coverage as well as the network's political and special events coverage.

It is not yet clear if Kelly's Sunday night program will air during the NFL football season, when NBC broadcasts "Sunday Night Football." When asked, an NBC News source said "all timing is TBD."

Some of it depends on when Kelly's loose ends at Fox are tied up.

Fox News stars rarely leave the network. When they do, Fox sometimes treats them harshly.

To be sure, Kelly was in an awkward work setting at Fox over the last year. O'Reilly, the 8 p.m. host, and Sean Hannity, the 10 p.m. host, both publicly clashed with her at various moments in 2016, furthering the speculation that she might not want to remain at Fox.

Kelly also played a key role in the ouster of Fox News chief executive Roger Ailes, who left the network amid multiple sexual harassment allegations. Kelly herself accused Ailes of sexually harassing her and making inappropriate comments in private meetings.

But she had strong relationships with the Murdochs. And Rupert issued a magnanimous statement on Tuesday afternoon.

"We thank Megyn Kelly for her 12 years of contributions to Fox News," he said. "We hope she enjoys tremendous success in her career and wish her and her family all the best."