NEW YORK — Megyn Kelly, the Fox News star who's had a contentious relationship with President-elect Donald Trump, said Tuesday that she's leaving the network for NBC News, where she will host a daytime talk show and a weekend newsmagazine, as well as contribute to breaking news coverage.

NBC News made the announcement Tuesday, ending months of speculation over whether she would re-up with Fox, where she has flourished while suffering bruised feelings in recent months, or start a new chapter in her career. Her contract with Fox expires this summer. Her last show on Fox will be Friday night.

Kelly's departure deprives Fox News of its second-most-watched host, behind only Bill O'Reilly, and a hole at 9 p.m. in its prime-time lineup.

"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," Kelly said in a message on Twitter on Tuesday.

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

Kelly's star power grew after she became a flashpoint in the presidential campaign after Trump objected to her questioning in the first Republican presidential debate a year and a half ago. He tweeted angry messages about her and boycotted another Fox debate after the network refused to replace her as one of the debate moderators.

She also became a central figure in the downfall of former Fox News chief Roger Ailes, telling in-house investigators of inappropriate conduct by Ailes that supported women who had made similar accusations.

Details about Kelly's new jobs at NBC will be revealed in upcoming months, said Andrew Lack, chairman of the NBC Universal News Group.

"Megyn is an exceptional journalist and news anchor, who has had an extraordinary career" Lack said. "She's demonstrated tremendous skill and poise, and we're lucky to have her."

Kelly wasn't immediately available for comment about what made her choose to leave Fox. But she said in an interview with The Associated Press in November that the factors she was weighing "mostly involve a 7-, 5- and 3-year-old," her children. Her Fox show airs live at 9 p.m., giving her no time at home with her children in the evenings.

She stressed that point in closing remarks on her program Tuesday, which she addressed to the audience.

Kelly said she valued the "human connection" the show gave her with viewers, but said she needed more of that connection with her children.

She expressed gratitude to her next employer, NBC, and current one.

"I am deeply thankful to Fox News for the wonderful 12 years I have had here. I've grown up here, and been given every chance a young reporter could ever ask for," Kelly said.

As a star in demand, Kelly was no doubt able to seek a schedule that would give her more time at home in the evening.

A former lawyer who was raised in upstate New York, Kelly turned to television and got a job in Fox's Washington office. She was noticed by Ailes, and given a daytime show. Her poise and sharpness, and willingness to ask tough questions of all political sides, made her a star and led Ailes to give her a coveted prime-time slot on cable news' most-watched network.

Her contentious relationship with Trump began when she asked the Republican businessman about statements he had made about women, infuriating him. He tweeted his disdain for her and although they made peace when Kelly interviewed Trump for a prime-time special last May, the relationship never became warm. Trump made Kelly's prime-time colleague, Sean Hannity, his preferred stopping place for interviews during the campaign and didn't come on her Fox News Channel show.

"I really had to choose — am I going to be an honest journalist ... or am I going to suck up to Trump?" she told the AP. "I chose the former, and it's worked out fine for me."

It put Kelly in an awkward position with Fox News Channel viewers who favored Trump, however. At one point during a Hannity interview with Trump, a live audience at a Trump rally booed the mention of her name.

Kelly's immediate silence after Gretchen Carlson's lawsuit last summer alleging unwanted advances from Ailes, at a time other Fox News personalities were supporting their boss, was telling. She told investigators that Ailes had made sexually suggestive comments to her and tried to kiss her, then made an angry reference to her contract when she rebuffed him. Ailes has denied any untoward advances involving Kelly.

Her move was a big boost for broadcast network news divisions, which had struggled somewhat during the presidential campaign given the non-stop coverage provided by the cable news outlets.

NBC News had recently been experimenting with a new Sunday night newsmagazine, "Dateline NBC: On Assignment," hosted by Lester Holt in a traditional format with a mix of news and feature stories, a template Kelly is expected to use. Weekday "Dateline" editions focus on criminal justice stories.

The move was a blow to Fox and its parent company, 21st Century Fox, whose leaders James and Lachlan Murdoch had made re-signing Kelly a priority and were believed in the industry to be offering her more money to stay. In her tweet on Tuesday, Kelly said she was deeply grateful to Fox News, its leaders and Fox's viewers, "who have taught me so much about what really matters."

Kelly gave a signal of her future direction with last May's interview special on the Fox broadcasting network. It wasn't a critical or commercial success, however.

Fox News does make in-house talent development a priority, however, and recently installed Tucker Carlson as a 7 p.m. host following the abrupt departure of Greta Van Susteren last summer. With Kelly taking a break over the holidays, Fox used Sandra Smith, Shannon Bream, Martha MacCallum and Trish Regan as substitutes.

AP television writers Frazier Moore in New York and Lynn Elber in Los Angeles contributed to this report.