WASHINGTON — Secretary of State Rex Tillerson was on the verge of resigning this past summer amid mounting policy disputes and clashes with the White House, according to senior administration officials who were aware of the situation at the time.

The tensions came to a head around the time President Donald Trump delivered a politicized speech in late July to the Boy Scouts of America, an organization Tillerson once led, the officials said.

Just days earlier, Tillerson had openly disparaged the president, referring to him as a “moron,” after a July 20 meeting at the Pentagon with members of Trump’s national security team and Cabinet officials, according to three officials familiar with the incident.

In an unscheduled statement to reporters Wednesday morning, Tillerson directly addressed that version of events, saying, "I have never considered leaving this post."

He praised Trump's foreign policy agenda, saying he was part of a team to "make America great again." But he did not deny calling the president a "moron," declining to address that remark directly and saying, "I'm not going to deal with petty stuff like that."

In a briefing Wednesday afternoon, State Department spokesperson Heather Nauert said Tillerson did not use the word "moron" to descibe the president. "The secretary did not use that type of language to speak about the president of the Unites States," Nauert said. "He did not say that."

The president was asked about Tillerson's remarks after touring the University Medical Center in Las Vegas Wednesday and said, "I am very honored by his comments, it was fake news, it was a totally phony story." Trump added that he has "total confidence in Rex."

While it's unclear if he was aware of the incident at the Pentagon, officials said Vice President Mike Pence counseled Tillerson, who is fourth in line to the presidency, on ways to ease tensions with Trump, and other top administration officials urged him to remain in the job at least until the end of the year.

Officials said that the administration, beset then by a series of high-level firings and resignations, would have struggled to manage the fallout from a Cabinet secretary of his stature departing within the first year of Trump’s presidency.

Pence has since spoken to Tillerson about being respectful of the president in meetings and in public, urging that any disagreements be sorted out privately, a White House official said. The official said progress has since been made.

Yet the disputes have not abated. This weekend, tensions spilled out into the open once again when the president seemed to publicly chide Tillerson on his handling of the crisis with North Korea.

NBC News spoke with a dozen current and former senior administration officials for this article, as well as others who are close to the president.

Tillerson, who was in Texas for his son’s wedding in late July when Trump addressed the Boy Scouts, had threatened not to return to Washington, according to three people with direct knowledge of the threats. His discussions with retired Gen. John Kelly, who would soon be named Trump’s second chief of staff, and Defense Secretary James Mattis, helped initially to reassure him, four people with direct knowledge of the exchanges said.

Related: Trump Tweets Tillerson 'Wasting His Time' Talking to North Korea

After Tillerson’s return to Washington, Pence arranged a meeting with him, according to three officials. During the meeting, Pence gave Tillerson a “pep talk,” one of these officials said, but also had a message: the secretary needed to figure out how to move forward within Trump’s policy framework.

Kelly and Mattis have been Tillerson’s strongest allies in the cabinet. In late July, “they did beg him to stay,” a senior administration official said. “They just wanted stability.”

At that time, however, Nauert responded to speculation that Tillerson was thinking about resigning by saying he was “committed to staying” and was “just taking a little time off” in Texas.

Tillerson's top State Department spokesman, R.C. Hammond, said Tillerson did not consider quitting this past summer. He denied that Tillerson called Trump a “moron.” Hammond said he was unaware of the details of Tillerson’s meetings with Pence.

Hammond said he knew of only one time when the two men discussed topics other than policy: A meeting where Pence asked Tillerson if he thought Nikki Haley, the U.S. ambassador to the United Nations, was helpful to the administration, or if he was worried about the role she was playing. He added that whenever the vice president gives advice on how processes could run more smoothly, the advice is a good thing.

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

Hammond also said that he wouldn’t characterize the secretary’s conversations with Mattis or Kelly as attempts to convince Tillerson to stay in his position.

In a statement Wednesday, the vice president’s communications director, Jarrod Agen, said “any statements” that Pence “questioned Ambassador Nikki Haley's value” to the administration are “categorically false.” He also said that, “at no time” did Pence and Tillerson “ever discuss the prospect of the Secretary’s resignation.”

A Pentagon official close to Mattis denied any awareness of a specific conversation about Tillerson’s future in the administration. But the official said the two men speak all the time and have a regular breakfast together.

The White House declined to comment on the record for this story.

Tillerson and Trump clashed over a series of key foreign policy issues over the summer, including Iran and Qatar. Trump chafed at Tillerson’s attempts to push him – privately and publicly – toward decisions that were at odds with his policy positions, according to officials. Hammond said Tillerson has had no policy differences with Trump. “The president’s policy is his policy,” Hammond said.

In August, Trump was furious with Tillerson over his response to a question about the president’s handling of the racially charged and deadly violence in Charlottesville, Virginia, administration officials said. Trump had said publicly that white nationalists and neo-Nazi sympathizers shared blame for violence with those who came out to protest them.

“The president speaks for himself,” Tillerson said at the time, when asked on “Fox News Sunday” about Trump’s comments.

Hammond said Trump addressed the issue with Tillerson in a meeting the next day. He said that during the meeting, Trump congratulated another White House official, Homeland Security Adviser Tom Bossert, for his performance on the Sunday news talk shows. Bossert had defended Trump’s controversial pardon of former Arizona sheriff Joe Arpaio.

President Donald Trump and Secretary of State Rex Tillerson confer during a working lunch with African leaders during the U.N. General Assembly in New York on Sept. 20, 2017. Kevin Lamarque / Reuters

The president, according to Hammond, told Tillerson he was upset with his comments when he saw them the first time. But, Hammond said Trump told Tillerson, after watching the interview a second and third time, the president understood that Tillerson was trying to say Trump is the best person to convey what his values are.

Still, the message was clear that Trump wanted Tillerson to defend him more, Hammond said.

The frustrations run both ways. Tillerson stunned a handful of senior administration officials when he called the president a “moron” after a tense two-hour long meeting in a secure room at the Pentagon called "The Tank," according to three officials who were present or briefed on the incident. The July 20 meeting came a day after a meeting in the White House Situation Room on Afghanistan policy where Trump rattled his national security advisers by suggesting he might fire the top U.S. commander of the war and comparing the decision-making process on troop levels to the renovation of a high-end New York restaurant, according to participants in the meeting.

It is unclear whether Trump was told of Tillerson’s outburst after the Pentagon meeting or to what extent the president was briefed on Tillerson’s plan to resign earlier in the year.

Tillerson also has complained about being publicly undermined by the president on the administration’s foreign policy agenda, officials said.

Those strains were on display this past weekend when Tillerson said, to the White House’s surprise, that the U.S. is attempting diplomatic talks with North Korea.

Trump quickly took the opposite position, writing on Twitter “I told Rex Tillerson, our wonderful Secretary of State, that he is wasting his time trying to negotiate with Little Rocket Man...,” using his latest epithet for North Korean leader Kim Jong Un.

“...Save your energy Rex, we'll do what has to be done!” Trump added in a second tweet.

Asked whether the president still has confidence in Tillerson, White House spokeswoman Sarah Sanders said Monday that he does.

Trump has already seen an unusually high level of turnover in his administration, with the departures of his national security adviser, deputy national security adviser, his chief of staff, press secretary, communications director — twice — his chief strategist, the director of the Federal Bureau of Investigation and the acting head of the Justice Department. Last Friday Trump accepted the resignation of Tom Price, the Health and Human Services secretary.

One senior administration official described late July as “a tough period of time” for Tillerson. His frustrations appeared to mount in the preceding weeks. Trump publicly undermined Tillerson in June over a dispute between Qatar and other Persian Gulf states, including Saudi Arabia and the United Arab Emirates. Tillerson had called on the countries to ease their blockade of Qatar, yet just hours later Trump said the Saudi-led effort was necessary.

Tillerson also pushed Trump to certify in July that Iran was complying with the 2015 nuclear deal.

Tillerson has been at odds with Trump on other issues as well, arguing against sanctions on Venezuela and reportedly suggesting Israel return to the U.S. $75 million in aid. Tillerson also is seeking to use the implementation of arms deals Trump struck with Saudi Arabia and the UAE as leverage to prod the two countries to resolve the dispute with Qatar, according to U.S. and Arab officials.

Administration officials speculate that Tillerson would be succeeded by Haley if Tillerson were to depart.

Tillerson’s tenure has been rocky from the start. He was confirmed by a Republican-led Senate on 56-to-43 vote. That represents the most votes against a secretary of state in Senate history.

Since then, Tillerson, the former chief executive of ExxonMobil, has been slow to fill jobs within his department and appears to have alienated officials in the White House, the Cabinet and Congress.

He has become known for being difficult to reach and tends to take his time returning phone calls, administration and congressional officials said. Congressional Republicans balked at his proposed cuts to the State Department budget.

“It’s hard to get him to return phone calls,” a senior Republican congressional aide said of Tillerson. “It’s hard to get him to answer letters.”

Hammond said Tillerson is quick to return calls and respond to lawmakers.

Tillerson has clashed with the president’s son-in-law and senior adviser Jared Kushner, who has a broad portfolio that includes policies in the Middle East, officials said.

A second White House official downplayed any tensions between Tillerson and Kushner, noting that Kushner’s efforts on an Israeli-Palestinian peace agreement are run through the relevant agencies and that a State Department representative went on his most recent trip to the region.

A third White House official disputed the notion that Tillerson has alienated people in the White House, Cabinet and Congress.

Trump’s July 24 speech at the Boy Scouts gathering struck a political tone unusual for the event, with the president talking about his electoral victory and the “cesspool” of Washington. He also joked about firing his Health and Human Services secretary if congressional Republicans didn’t pass a health care bill. The head of the Boy Scouts later apologized for the political tone of the speech.

Tillerson is an Eagle Scout and a former president of the Boy Scouts. He had appeared at the gathering just three days before Trump. Hammond, his spokesman, said Tillerson was not upset with Trump’s speech. He said Tillerson told him that at the end of the day the scouts are going to remember that the president came to speak at their event, and their parents can answer any questions they might have about the message he delivered.

It’s unclear if the latest disagreement between the White House and Tillerson on North Korea spells an end to the late-July reset.

Nicholas Burns, former undersecretary of state for political affairs under President George W. Bush, said Trump “completely undercut Tillerson” with his tweets.

“This was a direct public, I thought, repudiation of what Tillerson said,” Burns said. “It feeds the perception that Tillerson does not have a trusting relationship with the president, and that’s very harmful.”