In announcing that the country would remain shut down through April because of the coronavirus pandemic, President Trump and his advisers pointed to factors ranging from grim computer models showing millions of potential deaths to the unsettling sight of body bags lined up outside a Queens hospital.

But for Trump, political considerations also played a meaningful role, according to three people familiar with the discussions, speaking on the condition of anonymity to share candid discussions.

Aides and advisers say the president was heavily influenced by briefings from scientific and public health officials, as well as by the stark reality of the virus, including projections of greater deaths depending on what measures the government takes.

But Trump campaign officials and political allies had also briefed the president in recent days about their fears of reopening the economy too soon, arguing that a spike in deaths could be even more politically damaging in November than the current economic downturn, according to two of the people familiar with the discussions. Campaign officials declined to comment.

Public health officials warned Trump that many rural areas — which form the bedrock of the president’s political support — do not have the necessary hospitals and doctors to handle an outbreak, should it come.

Some administration officials had also circulated a Yahoo News/YouGov poll showing that 59 percent of Americans believed opening up “the country for business” by Easter, as Trump suggested last week, was “too soon,” two of the people said. And Trump has been pleased by how his approval ratings have ticked up recently.

Calling in to “Fox & Friends” Monday morning, the president weighed in on the political implications of the virus when asked a question about the 2020 Democratic field.

“I’ve gotten great marks on what we’ve done with respect to this,” Trump said. “I’ve gotten great marks. And even from almost every Democrat governor, so I’ve gotten great marks also. But we want to always make sure that we have a great president, that we have somebody that’s capable.”

An undercurrent of political calculation has coursed through much of Trump’s decision-making on the coronavirus. Despite taking some early modest steps, the president initially spent weeks downplaying the threat of the virus, in large part because he was worried about the effect on the economy. He has also clashed with Democratic governors, especially when he has felt they are being insufficiently appreciative of the federal government’s relief efforts. And he first settled on an Easter timeline — which he has since extended to the end of April — in part because of an eagerness to reopen the economy sooner rather than later.

Some top advisers, however, have counseled patience, saying that despite Trump’s reputation as an impulsive decision-maker, he is often willing to allow situations to play out.

Trump “is presiding over the country’s response to an unanticipated, unprecedented pandemic of global proportions, and he is getting credit for his handling of the pandemic,” said Kellyanne Conway, counselor to the president. “In due time, he will preside over the great American comeback, which is more likely to be in the summer or fall, depending on the effectiveness of mitigation and relief efforts and the uncertain path of the virus itself.”

This portrait of Trump’s decision to extend the government’s strict social-distancing guidelines to April 30 — more than two weeks beyond his initial “aspirational” goal of April 12 — comes from interviews with 15 senior administration officials, advisers, and outside allies and confidantes in frequent touch with the White House, many of them speaking on the condition of anonymity to share candid discussions and details.

Trump’s abrupt reversal was the result of several days of small group meetings during which he received briefings from public health and economic officials. On Saturday, the president’s likely course of action was still “very fluid,” in the one words of one outside Republican briefed on internal conversations.

By Sunday, however, most officials — including those representing an economic perspective — were trending toward extending the social distancing guidelines.

At a Sunday task force meeting not attended by Trump, Vice President Pence asked the entire room whether anyone had any immediate concerns over extending the guidelines, and there were no objections.

The group then briefed the president on their recommendation, and once he made a decision, officials decided to put it out immediately during Sunday evening’s Rose Garden news conference. They felt that Trump’s decision was an urgent public health matter and worried it might leak if they tried to wait longer to announce the news.

Deborah Birx, the White House’s coronavirus response coordinator, and Anthony S. Fauci, an infectious-disease expert, repeatedly presented the president with worst-case scenarios to underscore just how cataclysmic the crisis could get.

On Sunday, Birx, Fauci and Pence showed Trump models predicting that in a best-case scenario, as many as 100,000 to 200,000 Americans could die of covid-19, the disease caused by the virus — a warning they also echoed publicly. Trump was similarly taken by a study two weeks ago from the Imperial College in London, which found that as many as 2.2 million Americans could die absent any mitigation measures.

During the news conference Sunday and again to “Fox & Friends” on Monday, Trump — who has cast himself as a “wartime” president — sought to redefine just what a victory might look like.

“The worst thing we can do is declare victory. We’ve seen this — declare victory and then not have victory, and then have to do it all over again,” Trump told the Fox News hosts. “We have to get this thing gone, this virus. We have to beat it. We’re at war. This is a war.”

Other allies stressed that while Trump’s political fortunes are inextricably bound with his handling of the coronavirus response, in recent days, he has been increasingly driven by the responsibility as the commander in chief to protect the lives of Americans, after coming to understand just how deadly the pandemic is likely to be.

Sen. Lindsey O. Graham (R-S.C.), who regularly speaks with the president, said Trump’s previous admonishments — that the cure cannot be worse than the virus — “flipped when he heard that 2.2 million could die if he did nothing.”

“I just think the numbers of people that could die if you don’t aggressively treat this thing was a game-changer for him,” ­Graham said. “What he sees is the lethality of this thing unchecked, so now when you have 2.2 million lives at stake, you will accept more draconian measures than before.”

In addition to receiving briefings, the president has spent much of his time watching rapt as cable news and other outlets broadcast body bags and other harrowing images from the epicenter of the outbreak — Elmhurst Hospital in Queens, in the shadow of where Trump grew up — and found the dispatches unsettling, aides said.

“You know, I grew up near Elmhurst, and I look at Elmhurst Hospital in Queens, and I’ve known it,” Trump said Monday on Fox News, echoing similar comments he made in the Rose Garden on Sunday. “It’s terrible, what’s going on. It’s body bags all over, they’re bringing in refrigerator trucks to put the bodies in, refrigerated trucks, big vans, like, big trucks are coming in.”

Throughout the coronavirus crisis, Trump has at times maintained an uneasy relationship with the public health and scientific communities, frustrated with their advice and directives that essentially have forced the economy to shut down.

But Trump also listens to Birx and Fauci, aides say, and has repeatedly cited them in explaining his thought process. Two officials familiar with internal discussions said Birx and the president have a good relationship, saying she understands how to work with Trump and he, in turn, respects her.

Allies and advisers also privately made the case to the president that it is better to suffer short-term pain now — such as the more than 3 million Americans who have already filed for unemployment — in return for potential gain in several weeks by slowing infection and death rates.

The record $2 trillion economic stimulus legislation that Trump signed into law Friday also provided the president and some of his economic advisers a modicum of confidence.

As more U.S. cities faced severe outbreaks — including New York, New Orleans, Seattle and Detroit — administration officials questioned how much they could truly reopen the economy, if major cities remained shuttered.

“If consumers don’t want to leave their homes in July, we’re screwed,” said someone briefed on the response. “You have to do what you need to do to have a clean resolution to this so we can come out of this on the back end knowing that coronavirus has passed.”

By the time Trump ventured back into the Rose Garden on Monday evening, to talk more about the new guidelines, he seemed — for the time, at least — comfortable with his choice.

He mentioned the modeling that showed the peak in U.S. fatalities will not arrive for another two weeks and noted that these same projections show that “by very vigorously following these guidelines, we could save more than 1 million American lives.”

“Think of that: 1 million American lives,” the president said. “Our future is in our own hands, and the choices and sacrifices we make will determine the fate of this virus and, really, the fate of our victory.”