FILE - In this July 31, 2017, file photo, President Donald Trump talks with new White House Chief of Staff John Kelly after he was privately sworn in during a ceremony in the Oval Office in Washington. For an administration that has spent 2017 throwing off headlines at a stunningly dizzying pace, the frenetic fortnight in the second half of July reached an unparalleled breakneck speed. Set amid the backdrop of a president grappling with his deepest insecurities, the West Wing’s breakdown in policy collided with its collapse in personnel and acted as a crucial inflection point for Trump’s first year in office. (AP Photo/Evan Vucci, File)

FILE - In this July 31, 2017, file photo, President Donald Trump talks with new White House Chief of Staff John Kelly after he was privately sworn in during a ceremony in the Oval Office in Washington. For an administration that has spent 2017 throwing off headlines at a stunningly dizzying pace, the frenetic fortnight in the second half of July reached an unparalleled breakneck speed. Set amid the backdrop of a president grappling with his deepest insecurities, the West Wing’s breakdown in policy collided with its collapse in personnel and acted as a crucial inflection point for Trump’s first year in office. (AP Photo/Evan Vucci, File)

WASHINGTON (AP) — They were the 13 days that transformed the White House.

Even for an administration that spent most of 2017 throwing off headlines at a dizzying pace, events in the second half of July unfolded at breakneck speed. They encapsulated both the promise and peril of President Donald Trump’s first year in office — and yielded aftershocks that reverberate within the White House even as the calendar turns to 2018.

ADVERTISEMENT

The two-week span laid bare the splintering of Trump’s relationships with two influential Cabinet members; foreshadowed the reach of the Russia probe into the interior of his orbit; saw the dramatic, last-minute defeat of one of the president’s signature campaign promises; and featured a senior staff shakeup that reset the rhythms of this presidency.

From the outside, it was an unruly stretch that threatened to turn the White House into a sideshow. Inside the West Wing, the chaotic days between July 19-31 stand as a panicked memory but also one that also paved the way for future successes, according to nearly two dozen administration officials, outside advisers and lawmakers. Most of those interviewed for this account spoke anonymously because they were not authorized to talk publicly about private discussions.

For the record, though: “That was the extreme,” said former press secretary Sean Spicer.

___

THE KISS

His suit perfect and his hair just so, Anthony Scaramucci lifted his right hand off the briefing room podium and blew a kiss to the slack-jawed White House press corps.

Trump’s new communications director, known to his friends as the Mooch, made his dramatic debut on July 21 and aimed to usher in a new era at a White House riven by in-fighting, drowning in bad press and struggling to maintain credibility.

He lasted 11 days.

Scaramucci’s shockingly brief tenure — some White House aides have taken to calling a short period of time a “Mooch” — underscored the drama that dominated and frequently paralyzed the West Wing.

This was a White House where aides undermined each other with blind items in the press and jockeyed for face time with a president who left the Oval Office door open. Self-proclaimed “nationalists,” led by chief strategist Steve Bannon, were pitted against more centrist “globalists,” who included Trump’s powerful adviser and son-in-law Jared Kushner.

ADVERTISEMENT

How the rivalries played out in the press was particularly important for Trump, the former reality TV star who consumes hours of cable news each day. For months, he demanded that his schedule be arranged so he could watch the daily White House press briefing, often barking at aides about what he was seeing in between sips of Diet Coke in his private dining room.

Some of his rants were about the “fake” news media. But many were about Spicer, whom Trump believed failed to adequately defend him — or to look the part. Long believing he was his own best spokesman, Trump told one confidant that he saw something of himself in Scaramucci, a rich, fast-talking New York hedge fund manager who excelled on television. Within hours of when Scaramucci was hired, Spicer quit.

That was only the beginning of the drama: Scaramucci fired one staffer and threatened to push others out, including the entire press shop. He vowed to cut down on leaks, but many in the White House believed that was a cover story for his own vengeful agenda. Believing that Bannon and White House chief of staff Reince Priebus had initially blocked his entrance to the White House, Scaramucci moved to oust them, culminating in a New Yorker interview in which he graphically cursed out both men.

Scaramucci himself was pushed out the door days later. Scaramucci’s expletive-laden interview was only part of the problem.

Trump was unwilling to share the spotlight with an aide, and came to believe Scaramucci had forgotten his place.

___

THE TANK

Tension was thick in the air as Trump and several top advisers strode out of a windowless room at the Pentagon on July 20 and climbed into a waiting motorcade.

Over the previous 150 minutes, top U.S. officials had explained to the president the critical importance of forward worldwide deployments of U.S. military, intelligence and diplomatic assets. For months, Trump had questioned why the U.S. government needed “so many people” abroad and suggested that he wanted to reduce its footprint, an idea that triggered alarm in capitals around the globe.

Armed with charts, maps and diagrams, Defense Secretary James Mattis, Secretary of State Rex Tillerson and others schooled Trump with talking points and commentary sure to click with the former businessman. They stressed the role that the military, intelligence officers and diplomats play in making the world safe for American businesses like The Trump Organization to operate and expand abroad.

In a limited way, Trump agreed with Mattis and Tillerson, grudgingly agreeing to increase the number of U.S. forces in Afghanistan. But on a broad range of foreign policy matters, Trump has steadfastly refused to adopt conventional approaches, straining decades-long alliances, refusing to condemn authoritarian regimes on human rights abuses and escalating the rhetoric in a nuclear stand-off with North Korea.

The meeting in Room 2E924, known as “The Tank,” highlighted the sharp learning curve that the president, who had never held elected office or served in the military, faced as he grew into his new job. It also revealed the tensions within the administration between those from Washington’s national security establishment and those eager to pull back from international entanglements.

That rift only grew after the top-secret gathering. It was soon after the meeting concluded that Tillerson was reported to have privately called the president “a moron.” The secretary of state pointedly did not deny that he had done so — eventually, a State Department spokeswoman did — and it prompted a furious response from Trump, who repeatedly undermined Tillerson on his approach to North Korea.

But Tillerson was not the only attendee at The Tank to have misgivings after the session.

In the days that followed, Joseph Dunford, chairman of the Joint Chiefs of Staff, encouraged his best friend, Homeland Security chief John Kelly, to take the White House chief of staff job.

___

THE GENERAL

Buffeted by fierce rains and wind, Air Force One circled over Washington on July 28. When it finally touched down at Joint Base Andrews, a new phase of the presidency began.

In a series of tweets, Trump announced that he was appointing Kelly, a retired four-star general, to replace Priebus. As the 140-character bursts reached their smart phones, a pair of senior White House aides who been sitting in an idling SUV with Priebus stepped out onto the rainy tarmac and left the outgoing chief of staff alone.

Priebus never could bring a semblance of order to the rivals that populated Trump’s West Wing and the president had openly mused about replacing him. Never empowered to fully step into the role, Priebus often acted as merely the captain of his own squad of establishment Republicans, vying with Bannon and Kushner for influence.

Trump had previously floated the job to Kelly, who initially demurred. Kelly told confidants he had a change of heart because he felt that the president’s term had been imperiled by poor staff work.

“I don’t think you can overestimate the effect of the impact of those (staff) changes and that period,” Marc Lotter, Vice President Mike Pence’s spokesman, said at the time.

One of Kelly’s first official moves was to fire Scaramucci. In the months that followed, other headline-grabbing aides — Bannon, Sebastian Gorka and Omarosa Manigault-Newman — also were pushed out as Kelly tried to enforce a one-team ethos. Most impactfully, aides said, Kelly worked to cut down access to the Oval Office and seize control of how information reached Trump.

Several advisers deemed Kelly’s hire a turning point for the administration, a move that cut down on internal fights, restored order to the West Wing and laid the groundwork for wins down the road.

“Once myself, Reince and Steve were out of the picture, I think that moved the target off — it got people back to focus,” Spicer recalled.

But there were limits to what Kelly could — or would — control.

The chief of staff made clear he would mount no effort to manage Trump’s no-holds Twitter habit. And Trump, in turn, chafed at Kelly’s handling.

___

THE THUMBS-DOWN

Majority Leader Mitch McConnell stood on the Senate floor, his arms crossed, his face impassive. Trump, back at the White House, had hung up the phone, his last attempt at persuasion over.

At 1:29 a.m. on July 28, Republican Sen. John McCain of Arizona strode onto the Senate floor. The 80-year-old, just weeks after a brain cancer diagnosis, was poised to cast the tiebreaking vote on the GOP’s health care bill, in what was meant to be the fulfillment of seven years of work to undo President Barack Obama’s signature health care law.

McCain paused for a moment, and then flashed a thumbs-down, drawing gasps from fellow senators. The bill was dead, and the White House had been dealt a devastating blow.

Though Trump had spent the presidential campaign promising to repeal and replace Obamacare on Day One of his administration, the Republican effort had failed. It was a fiasco that underscored how the White House was struggling to push through Trump’s agenda even though his party controlled both houses of Congress.

Frequently exhibiting a shaky grasp of policy details, Trump often baffled aides by waffling on various options — including whether the GOP should repeal the Affordable Care Act and come up with a replacement later, or let it simply starve by not paying subsidies. His approach to lawmakers on Capitol Hill was equally inconsistent.

Trump snarled in private about McConnell and House Speaker Paul Ryan and showed no hesitation to air his grievances publicly. He used Twitter to deliver broadsides against the majority leader — urging him to “get back to work” — and targeted individual Republican senators whose health care votes the White House once courted.

But from the ashes of the health care defeat came the administration’s first major legislative triumph: the tax cut legislation passed on Dec. 20.

The bungled legislative process on health care sparked a new call for discipline in the administration’s approach to Capitol Hill. The White House would buy in to the plan at the start. Staff would cajole wavering legislators and work to resolve their concerns while there was still time to address them. Trump’s political operation would begin work to sell the tax package in the approaching midterm elections.

Trump himself worked behind the scenes making phone calls to key members and, perhaps more importantly, reined in his public criticism of members of his own party. With just 11 days left in 2017, Republicans from the House and Senate stood on the White House South Lawn and applauded as the president announced the bill would become law.

Trump allowed that he’d learned a thing or two — about the importance of relationships, in particular.

“When I came, I didn’t know too many,” he said Friday of the legislators. “I can call anybody now. I know every one of them very well.”

___

THE RAID

The sun had not yet risen on July 26 when FBI agents arrived without warning at the front door of Paul Manafort’s home in Alexandria, Va.

Using a search warrant, they emerged from the home of Trump’s former campaign chairman with a trove of material. A new, more dangerous, chapter had begun in special counsel Robert Mueller’s investigation into possible coordination between the president’s campaign and Russian officials.

The raid was a stark reminder for the White House that, no matter the successes or failures of the moment, the cloud of the Russia probe loomed on the horizon. Trump had grown furious at the distraction, fuming to advisers that he had done nothing wrong while railing that it was a conspiracy by Democrats and the so-called “deep state” to delegitimize his presidency.

Exactly one week before the raid, Trump sat in the Oval Office with reporters from The New York Times and, with little prompting, veered into an attack on his own attorney general, Jeff Sessions. Trump blasted Sessions, once one of his closest allies, for recusing himself from the Russia probe, believing that helped lead to Mueller’s appointment.

Trump continued his assault in a series of tweets in which he called Sessions “weak” and “beleaguered.” Privately, he discussed firing Sessions, but was met with a wave of resistance from his advisers. Some warned it would worsen the Russia probe, while Bannon told the president it would hurt with his base supporters, who loved Sessions’ tough-on-crime approach at the Justice Department.

Kelly, in his first weekend on the job, called Sessions to assure him his position was safe. But the rift between Trump and Sessions still has not healed. Recently, Trump bemoaned the Republicans’ loss in a special election in Alabama and in part blamed Sessions, whose departure from the Senate to head to Justice necessitated the election.

And the Mueller investigation shows no signs of ending.

Scores of top aides and allies, including Kushner and Trump’s eldest son, Donald Jr., have been questioned by Mueller and congressional investigators. In October, Manafort was charged with money laundering and other financial crimes related to his political consulting work in Ukraine. Several other Trump associates also have been charged by Mueller, including former national security adviser Michael Flynn, who pleaded guilty to lying to FBI agents and is cooperating with the investigation.

Though still shadowed by the probe, Trump emerged from the crucible of the 13 days in July with a more organized and less drama-filled White House, as well as lessons learned that would yield legislative victories.

But the president himself remains unchanged.

Impulsive and unconventional, Trump has spent his first year in office casting aside norms and mores. With his Twitter account as his weapon, the president has shown no willingness to ignore any slight or change the brash ways that he believes got him elected.

“I said with the exception of the late great Abraham Lincoln, I can be more presidential than any president that’s ever held this office,” Trump told a rally crowd in Ohio on July 25. “It’s so easy to act presidential, but that’s not gonna get it done.”

___

Follow Lemire on Twitter at http://twitter.com/@JonLemire and Miller and http://twitter.com/@ZekeJMiller