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

Florida Gov. Ron DeSantis issued a stay-at-home order for the entire state Wednesday as it grapples with a rapidly spreading coronavirus outbreak.

The order goes into effect at midnight Thursday and will last for at least 30 days, DeSantis said at a news briefing. He said that the order would limit movement within the state and that unless residents are pursuing "essential" services or activities, they should stay indoors.

DeSantis had been criticized for refusing to implement statewide social distancing guidelines, particularly as beachgoers and students on spring break continued to gather in large groups. DeSantis refused to close the state's beaches even as other states were shutting down schools and nonessential businesses.

Florida has the fifth most coronavirus cases of any state, reporting nearly 7,000 cases and 87 deaths, according to the state Health Department. When the state surpassed 5,000 cases, DeSantis continued to balk at issuing a stay-at-home order. Other states that crossed that threshold, such as California, New York and Washington, issued sweeping mandates.

Full coverage of the coronavirus outbreak

The governor had previously said it was up to the local officials to close nonessential businesses and beaches, saying last month that "no matter what you do, you're going to have a class of folks who are going to do whatever the hell they want to."

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

DeSantis had also dismissed concerns about frolicking beachgoers.

"These are our neighbors who may need to go out there, clear their head," DeSantis said at a news conference last month after the sight of sunbathers soaking up rays caused widespread criticism. "Because a lot of people are on edge now."

But Wednesday, as the state's cases continue to rise, the governor said "it makes sense to do this now" after President Donald Trump announced this week that the administration is extending its social distancing guidelines for 30 more days. DeSantis, a Republican ally of Trump, said he took that as a "signal" from the president that it needed to be done in Florida.

DeSantis had previously said he would issue the order if the administration made the recommendation. Trump said at Tuesday's coronavirus task force briefing that DeSantis "knows exactly what he's doing" when asked about the governor's hesitance.

DeSantis "has a very strong view on it," Trump said. "So unless we see something obviously wrong, we're going to let the governors do it."

The president on Tuesday projected a grim 100,000 to 240,000 deaths in the U.S., even with strict mitigation efforts.

DeSantis has been under fire from local media and officials throughout Florida for having resisted ordering sweeping measures.

"Coronavirus is killing us in Florida," read the headline of a Miami Herald editorial last month that blasted DeSantis' response. "Act like you give a damn." The Herald noted that DeSantis did not join a bipartisan group of Florida lawmakers in appealing to the federal government for more help.

Download the NBC News app for full coverage and alerts about the coronavirus outbreak

Former Vice President Joe Biden, the Democratic presidential front-runner, criticized DeSantis' response as "much too slow" in an interview Tuesday. Biden warned that Florida would "become an increasingly dangerous place" unless it adopted stricter guidelines.

State Agriculture Commissioner Nikki Fried, a Democrat who has been critical of DeSantis, praised his decision in a statement Wednesday.

"When I called for this stay-at-home order nearly two weeks ago, there was a reason. It was necessary to flatten the curve and save lives," she said. "I said then I would stand with the Governor when he issued the order, and I do so now. Thank you, Governor, for making the right call. Together, we will fight this virus and preserve the state we love."