Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

Acting Navy Secretary Thomas Modly has resigned, two defense officials said, a day after he ridiculed and then apologized to a captain he had ousted for raising concerns about a coronavirus outbreak on his aircraft carrier.

Modly offered to quit in a Tuesday morning conversation with Defense Secretary Mark Esper, the officials said. Esper accepted his resignation and has selected Under Secretary of the Army James McPherson to replace Modly as acting Navy secretary, according to the officials.

The revelation comes after Modly’s stinging remarks about Capt. Brett Crozier, broadcast over the loudspeakers on the USS Theodore Roosevelt on Monday, drew criticism from lawmakers and disapproval from President Donald Trump.

“He resigned on his own accord, putting the Navy and the sailors above self so that the USS Theodore Roosevelt, and the Navy as an institution, can move forward,” Esper wrote in a Tuesday statement.

Modly is now in isolation after visiting the ship, two defense officials told NBC News. McPherson learned that he was tapped to become the acting Navy secretary during a meeting with Esper on Tuesday, a defense official said.

In his final memo to the Navy, Modly said he "lost situational awareness" when he walked on the Theodore Roosevelt and spoke to the crew members "as if I was their commander, or their shipmate, rather than their secretary."

"The crew deserved a lot more empathy and a lot less lecturing—I lost sight of that at the time and I am deeply sorry for some of the words and for how they were spread across the media landscape like a wildfire," Modly added. "I had hoped to transmit a message of love, and duty, and mission, and courage in the face of adversity. Those words are in there, but they are now lost, because of me, and I will regret that for the rest of my life."

A defense official said Modly had traveled to Guam, where the ship was docked, with only his chief of staff, security and a senior military assistant — leaving behind his public affairs team and aides.

The controversy began last week when Crozier, the commanding officer of the Theodore Roosevelt, sent a strongly worded memo to a broad array of Navy officials begging for help amid a COVID-19 outbreak on the ship. The memo leaked to the press and generated a series of headlines.

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

Crozier was relieved of his command last Thursday. Modly said at the time he made the decision because Crozier went outside the chain of command and exposed sensitive information.

Video emerged a day later showing throngs of Theodore Roosevelt crew members cheering for Crozier as he walked off the ship.

Modly traveled to Guam on Monday and delivered a speech to the sailor calling Crozier either “stupid or naive” for writing the memo and accusing him of a “betrayal of trust.”

“If he didn’t think, in my opinion, that this information wasn’t going to get out into the public, in this day and information age that we live in, then he was either A, too naive or too stupid to be a commanding officer of a ship like this,” Modly said.

Modly, in a statement released after a purported transcript of the remarks was reported by several news outlets, didn’t back down.

“I stand by every word I said,” the statement read.

But several hours later, after Trump voiced support for Crozier, Modly released a new statement apologizing for his remarks.

"Let me be clear, I do not think Captain Brett Crozier is naïve nor stupid," Modly said. "I think, and always believed him to be the opposite."

Kenneth Braithwaite, the U.S ambassador to Norway, was formally nominated to replace Modly as secretary of the Navy but he is still awaiting Senate confirmation.

Modly's resignation drew a swift reaction from politicians on both sides of the aisle.

Mac Thornberry, R-Texas, the top Republican on the House Armed Services Committee, said he welcomed the move.

"The change in the office of the Secretary of the Navy should allow the country to put this episode behind us and allow Sailors to focus on the very important missions at hand," Thornberry said.

Senate Minority Leader Chuck Schumer said: "Captain Crozier spoke up to protect his crew. Acting Navy Secretary Modly’s words and actions were insulting to those under his responsibility—It’s good he resigned."

And Democratic presidential candidate and former Vice President Joe Biden described Modly's resignation as "appropriate and called for."

"His disparaging remarks were far beneath the dignity of the office he held," Biden tweeted. "Our sailors, our nation, and Captain Crozier deserve better."