Fox News chairman Roger Ailes woke up Monday morning thinking that his network and Donald Trump's campaign had reached an understanding.

After a weekend's worth of stressful phone calls, the tacit agreement -- he thought -- was that Trump would stop attacking Ailes' biggest television star, Megyn Kelly, in interviews and tweets.

Then came an ugly surprise. Trump said on MSNBC's "Morning Joe" that he thought Kelly should apologize to him.

"This was the final straw for Roger," according to a source close to the situation.

Ailes' office called Trump's office. We "can resolve this now," Ailes said to Trump, "or we can go to war."

As we all know by now, war was averted. There is mutual respect between the two master negotiators. Trump has stopped criticizing Kelly. And Fox has stopped ignoring Trump on its shows.

But if this is a truce, it's a tenuous one. In recent days Trump loyalists have leaked unflattering claims about Ailes, and Fox staffers have privately likened Trump to a crazy person.

With detente in place, each side is now being more careful with their words. Trump is, to put it kindly, as one high-placed Fox source purposefully did, "a nontraditional candidate."

The candidate is also being kind to Fox; when Trump called into Lou Dobbs' Fox Business show on Wednesday, he said "I love your show and watch it all the time."

Related: Bernie Sanders and Donald Trump agree on 1 big issue

Given the billionaire's popularity, "Ailes had to make peace," said Roger Stone, a Trump senior adviser who recently left the campaign in disputed circumstances.

But no one knows how long the peace will last.

This reconstruction of the dispute between the Republican presidential primary's #1 candidate and the Republican party's #1 network relies on sources from both sides who asked to remain anonymous plus on-the-record statements and tweets. It begins at the GOP debate last Thursday night, during an awkward pregame show when Kelly invited Trump and the other nine contenders onto the stage.

From Monday: Donald Trump and Roger Ailes clear the air

THURSDAY:

"Come on out, guys," Kelly said. When no one walked out right away, Kelly turned to fellow moderator Bret Baier to fill the airtime. Maybe the candidates are backstage "coming up with their game plan?" she asked. "We have our game plan."

The plan called for sharp questioning of the leading candidates for president. Trump thought it was too sharp.

Kelly's first question to Trump recounted how he'd disparaged women with terms like "fat pigs, dogs, slobs, and disgusting animals." She invoked the "war on women" and asked about his temperament.

Trump tried to deflect the dart, but it stuck, as did other questions from the moderators. Immediately after the debate, Fox commentators and a televised focus group had sour reviews for Trump, and Trump was equally sour.

Surrounded by reporters afterward, Trump said he thought "the questions to me were not nice," particularly Kelly's. "I thought Megyn behaved very badly, personally," he said.

Fox executives, on the other hand, were exuberant about how well Kelly had performed. It was the biggest stage she'd ever been on.

FRIDAY:

Trump barely seemed to sleep after the debate. He tweeted up a storm and vented on the morning shows Friday morning. He also called Ailes to complain, according to one of the sources.

(Spokeswomen for Ailes and for Trump's campaign declined to comment on the back-and-forth between the two men.)

Trump's camp felt targeted by Fox and thought it came from the top — that is, from Ailes, a conservative kingmaker who advised Republican politicians before creating Fox News.

"Donald felt betrayed," one source said. That's because Ailes and Trump have known each other for 30 years and describe each other as friends.

On Friday afternoon, Trump tweeted a Bloomberg headline that read "Fox News Couldn't Kill Trump's Momentum, Made Him Stronger." He also tweeted that Fox should be "ashamed" for covering him critically.

The more Trump complained, the more his supporters complained, sometimes in deplorable ways. Fox executives were particularly incensed when Trump adviser Michael Cohen retweeted a user who called for a boycott against Kelly and said, "We can gut her."

The tweet was later deleted, and Cohen said he didn't think it implied physical violence. But by Friday night, from Fox's perspective, it was getting scary -- and that's when Trump brought up Kelly's "blood."

"You could see there was blood coming out of her eyes. Blood coming out of her... wherever," he told CNN's Don Lemon.

One source said the best word to describe Ailes' reaction was "apoplectic." Another person said "furious."

SATURDAY:

Was Trump really referring to Kelly's menstrual cycle, as many people assumed? Trump denied it on Twitter Saturday morning. But the "blood" comment became national news — everywhere but Fox, which never mentioned it on the air. Nor did any Fox hosts or reporters publicly come to Kelly's defense, even though many of them wanted to do so — the network wanted silence.

Some observers suggested this was an uncharacteristic show of weakness by Ailes. But Ailes did not want to escalate the feud by appearing to fire back. His camp believed that Trump had to be handled delicately, given how disgruntled and unpredictable the candidate was.

"Roger made the decision that as angry as he was, it was a priority to position Megyn above the fray and protect her image and that of Fox News," one of the sources said, "which meant not engaging in a public frenzy."

Fox host Sean Hannity was an intermediary of sorts, relaying to Ailes what he was hearing from Trump -- and from conservatives who were fuming, accusing the network of setting out to hurt Trump at the debate.

SUNDAY:

New York magazine reported on Tuesday that Ailes was unwilling to call Trump over the weekend. There were numerous other calls, however, between Trump aides and Bill Shine, one of Ailes' top lieutenants.

Fox wanted one thing above all: for the attacks on Kelly to stop. Every time Trump gave an interview, including to CNN on Sunday morning, the "blood" comments resurfaced.

Trump also wanted something: he wanted an apology from Kelly for Thursday's publicly televised inquisition, some sort of admission that she went too far. He felt he had enormous leverage.

To Ailes, an apology was a non-starter.

But both men also had mutual interests, like getting Trump back on Fox News, where he could reach millions of Republican primary voters and propel Fox's ratings.

A protracted battle would have been media reporter fodder but didn't seem to be in either side's interest.

MONDAY:

The behind-the-scenes calls seemed to be bearing fruit by Sunday night. But then came Trump's assertion, bright and early Monday on "Morning Joe," that Kelly should apologize. It might have made his supporters happy, but it made Ailes exceedingly unhappy.

On the ensuing phone call, there was "very blunt" talk from both sides, including Ailes' warning of war, two of the sources said.

There was an "instant understanding between two titans that this was over," one of the sources said. Trump wouldn't apologize, Kelly wouldn't apologize, but both sides would move on.

Trump tweeted about the phone call right afterward and said he'd been assured that "'Trump' will be treated fairly" by Fox.

The sources for this story contradicted New York magazine's assertion that Ailes called Trump repeatedly and "begged" the candidate to tweet that they'd settled their feud. "Neither of them would beg for anything," one of the sources said.

In a statement on Monday night, Ailes said "the air has been cleared" with Trump but added he supported Kelly "100%."

When Kelly's show started at 9 p.m., hundreds of thousands of extra viewers turned on Fox. She very briefly acknowledged the controversy and moved on -- no "milking it for the ratings," as one rival executive said -- but she still easily scored the night's highest cable news ratings, beating the usual winner, Fox's 8 p.m. "O'Reilly Factor."

So much for the threatened boycott by Trump supporters.

TUESDAY:

Fox noticeably ramped back up its coverage of Trump without reflecting back on the "blood" comments that disgusted Kelly and company.

When the candidate called into "Fox & Friends" at 7 a.m. Tuesday, co-host Steve Doocy said, "Glad we're friends again."

Trump didn't talk about the Fox fracas on Fox, but when CNN's Chris Cuomo asked about it, Trump effusively praised Ailes and called him "amazing."

Later in the day Hannity taped a lengthy interview with Trump at Trump Tower. Hannity started with the "elephant in the room," the "Fox issue," and Trump said things were "absolutely fine" now.

Part one aired at 10 p.m. Tuesday, following Kelly's show, and the ratings proved why the Fox-Trump relationship is mutually beneficial.

In the key demographic of 25- to 54-year-olds, Kelly's ratings were above average, but Hannity's were even better, making him #1 for the night. Hannity usually has fewer than 400,000 viewers in the demo; with Trump, he had more than 600,000.

Part two is airing on Wednesday night.

WEDNESDAY:

While Trump has been placated, tensions with Fox linger right beneath the surface. Some network executives are said to detest Trump's bombastic behavior.

And it hasn't helped that many commentators have portrayed Ailes as buckling or bowing to Trump. (Sample quote via The Washington Post: "Give credit where it's due — Trump bargained with Fox News, Trump won, and it wasn't close.")

Trump still seems to have a sore spot about coverage of his campaign; he tweeted some gripes to Fox host Eric Bolling on Monday night, for example.

And on Wednesday, Trump committed to an exclusive Sunday morning interview with NBC's Chuck Todd this weekend. This could be interpreted as a snub of Fox's Chris Wallace since Fox had been in talks with Trump's campaign about an in-person interview with Wallace for "Fox News Sunday."

Trump won't soon forget the feeling of being beaten up on Fox's debate stage. It remains to be seen if he will show up to Fox's November and January debates.

And Ailes won't soon forget that Trump triggered days of references to Kelly's "blood."

Maybe the two men have met their match.

The Future of Media, a customized magazine