MORRISVILLE, N.C. — With his home state flooded and the death toll rising, FEMA Administrator William “Brock” Long was on the verge of quitting this week.

On Sunday, his bitter feud with Homeland Security Secretary Kirstjen Nielsen seemed as though it would abate. The two agreed to a truce so that the Trump administration’s response to Hurricane Florence would not be further overshadowed by the deepening acrimony between them since the disclosure of an internal investigation into Long’s use of government vehicles to travel between Washington and his home in North Carolina.

Nothing would happen to Long in the near term, Nielsen assured him, according to three senior government officials familiar with the conversation. Let’s just get through the storm, she said.

About 24 hours later, as Long’s plane landed in North Carolina, he learned that the DHS Office of Inspector General had referred his case to federal prosecutors for a possible criminal investigation. He felt devastated and betrayed, according to the three government officials, who had knowledge of Long’s reaction.

FEMA administrator William “Brock” Long spoke alongside North Carolina Governor Roy Cooper (D) at a command center in Wilmington, N.C. on Sept. 18. (FEMA Video)

“It was FEMA personnel who convinced him not to quit,” said one congressional aide briefed on the matter. A senior administration official confirmed the account.

The political upheaval surrounding Long now threatens to undercut the nation’s top disaster official at the moment he’s needed most, his allies say. State and local officials in North Carolina have praised the Federal Emergency Management Agency for its response to the storm. But the discord has sparked worry and some level of panic within FEMA and DHS as they prepare for what is forecast to be a hectic hurricane season, and as FEMA seeks to rehabilitate its image amid renewed criticism of its handling of Hurricane Maria in Puerto Rico last year.

Long called his relationship with Nielsen “professional and functional.” But behind the scenes, he and other FEMA officials have told colleagues they think she has her mind set on ousting him.

Long spoke briefly with The Washington Post on Wednesday as he was driven in an SUV to a helicopter waiting to take him to greet President Trump, who had arrived with Nielsen in North Carolina to assess the federal response. “We both understand what needs to be done,” he said of himself and Nielsen, “and we will continue to work together.”

Long said he has not seen the inspector general’s findings or retained an attorney. He would not discuss the investigation except to say that “what’s being put out there, it’s far from the reality.” He has repeatedly denied doing anything improper.

FEMA Administrator William "Brock" Long responded to reports Sept. 13 of the inspector general investigating his use of government vehicles. (Reuters)

Tension between Nielsen and Long dates to summer 2017, when Nielsen was chief of staff to Homeland Security Secretary John F. Kelly, said an administration official who has observed their interactions. It deteriorated further once she took over at DHS in December, this official said.

Nielsen was irritated with Long for not attending early-morning meetings with top-level DHS staff, and she disapproved of his absences from Washington, an official said. As homeland security secretary, Nielsen is Long’s boss, but the FEMA administrator directly advises the president during disasters. This competing chain of command has contributed to the friction between Nielsen and Long, current and former administration officials said.

On Sunday, things boiled over. Within hours of their phone call establishing a truce, Long’s aides learned that Nielsen was preparing to visit North Carolina to speak with emergency responders, four officials said. No one had told FEMA of her plans. Long and his aides scrambled to get there as well.

A senior administration official familiar with the planning contested that account. The official said senior FEMA staff were told Friday that Nielsen was considering a trip, but her travel plans weren’t finalized until midday Sunday during a meeting with Long.

A FEMA spokeswoman declined to comment. A DHS spokesman did not immediately respond to a request for comment.

Though Long’s future with the administration remains in question, officials acknowledge the situation presents a dilemma. He is considered highly competent and, perhaps as important, Trump appears to like him. The president praised Long — and Nielsen — during a media appearance Wednesday.

But Long’s personal relationship with the president may have contributed to what one administration official called “creeping hubris,” notably as he used government vehicles for his trips home even after Nielsen chided him for it. Several officials who have worked with Long in the past say he is highly skilled and experienced at emergency management but not adept at the political dynamics of Washington.

It was unclear whether Trump and Long discussed his future during the president’s visit to North Carolina.

The inspector general’s investigation centers on Long’s travel to Hickory, N.C., where his wife and two young sons live. Investigators surveilled Long during those trips, which occasionally included other FEMA staffers, raising questions internally about his use of government resources, two administration officials said.

Nielsen promised to give Long a copy of the investigation’s preliminary findings in recent days but has not followed through, said the three government officials, who spoke on the condition of anonymity to offer their candid assessment of the rift. Nielsen and others at DHS have known for weeks that the inspector general was preparing to refer the matter to the Justice Department for possible prosecution, according to one of those officials.

Another administration official familiar with the investigation challenged those claims, and said the DHS inspector general is independent of the secretary and therefore Nielsen would not be able to share the investigation’s findings with Long. “It is not her report,” the official said.

A spokesman for the Justice Department declined to comment.

Long and others at the agency thought his use of the vehicles was justified, current and former officials said, because the FEMA administrator is responsible for the agency’s National Continuity Programs, which requires the country’s leaders to maintain secure communications in the event of a catastrophe. Much of the NCP plans are classified, officials said, but it requires Long to be on call around the clock with access to secure equipment that allows the president to talk to him within minute’s notice.

Officials familiar with Long’s schedule said that his trips home were not as prolific as his detractors have suggested and that he has tried not to waste taxpayer money, using public transportation to commute to and from his residence in Washington.

In his interview with The Post, Long said: “I took the Metro to work. I ride an electric scooter to work. I walked to work. I’ve been bitten by a dog walking to work.”

Florence’s path through North Carolina has, in some ways, proved fortuitous for Long. He has been able to leverage his lifelong knowledge of the state and relationships forged with disaster management officials there as he has toured stricken areas and sought to assure those in distress that the federal response would be robust and sustained.

“It’s important for me to be on the ground,” he told The Post, describing his visit to a shelter where he talked to storm survivors and made personal calls to responders to adjust their plans.

Local officials say that Long has been highly effective and praised FEMA’s response to the crisis thus far. Nearly 20,000 federal and military personnel have been involved. More than 3,000 people have been rescued from the floodwaters, and 2 million meals have been delivered to those in need across North and South Carolina, according to federal officials.

In North Carolina, leaders said they’ve benefited, too, from an innovative program that embeds FEMA workers in the state before disasters strike. Long launched the program there in April and plans to spread it across the country.

Long is widely liked and respected across FEMA’s sprawling staff and among those staffing the emergency operations center in Raleigh, North Carolina’s capital. Many have expressed anxiety at the prospect of Long’s ouster and what it could mean for the agency.

FEMA’s No. 2 position has been vacant for nearly two years, and Trump’s current nominee, Peter Gaynor, still awaits Senate confirmation. The third in command — Daniel Kaniewski, a close friend and onetime housemate of Nielsen, according to three current and former colleagues — could take over, at least on an interim basis, if Long were to leave. But his background in policy and academia, ­and his lack of hands-on emergency management experience, ­has generated concern inside and outside FEMA.

“That’s what freaks us out. You see what Rex Tillerson did at the State Department, taking a machete to their staffing and budget,” said one current FEMA staffer, referring to the former secretary of state, who met stiff resistance internally as he sought to restructure the department. “Nobody knows who Trump could pick to replace Brock. And that’s petrifying when you’re talking about the agency at the heart of this country’s disaster response.”

One high-ranking employee posted a picture of himself with Long on social media with the hashtag “#teambrock.” Others have posted memories of working with him over the past year through several difficult disasters.

Because of the storm, some staffers have been working 16-hour days, far past their paid hours and to the point of exhaustion. Before Long’s troubles, many felt stung by public criticism of FEMA’s response to Hurricane Maria last year. And some saw Florence as their agency’s chance to prove its competence.

“The people we’re helping now, that’s the whole reason we get into these jobs. It’s the reason we endure all the other stuff because we want to make a difference,” one staffer said.

In an interview, Thomas Bossert, the president’s former homeland security adviser, praised Long’s performance and said he knew him to be extraordinarily ethical, even as he said he respected the inspector general’s work. “He is as good as you could want in the job,” said Bossert, who has known Long since 2003.

Long has worked in emergency management for almost 20 years. First, as a school safety coordinator for the Georgia’s emergency management agency, then as FEMA’s hurricane program manager for southeastern states. From 2008 to 2011, he was director of Alabama’s emergency management.

“I came to D.C. to serve my country,” he told The Post. Those close to him say the past week has taken a heavy toll on his family, and Long said he would return to North Carolina when his time leading FEMA eventually ends. “I look forward to simplicity and helping my dedicated wife raise our two beautiful boys,” he said. “God knows they are truly serving their country right now too — probably even more than I am.”

At the moment, Long said, FEMA is in the shortest and most dramatic stage of emergency management. After the rescues comes the longer and often most frustrating phase: helping the victims return to some sense of normalcy.

“People are about to get frustrated,” Long acknowledged.

Was he also frustrated? “Yes,” the embattled FEMA chief said. Then he turned, opened the SUV door and stepped out to shake hands before boarding a helicopter to meet the president.

Wan, Dawsey and Miroff reported from Washington.