Rapper Tekashi 6ix9ine was ordered immediately freed from a Manhattan federal lockup four months early Thursday by a judge who cited his asthma and the greater danger he would face behind bars during the coronavirus outbreak. U.S. District Judge Paul A. Engelmayer made the ruling a day after telling lawyers on both sides that he intended to do so.

He cited "a raging and virulent pandemic that has entered federal prisons in New York City." Prosecutors did not oppose the action.

"In light of the heightened medical risk presented to Mr. Hernandez by the COVID-19 pandemic, there are extraordinary and compelling reasons to reduce Mr. Hernandez's sentence," he said.

Get Breaking News Delivered to Your Inbox

In a statement to CBS News, the rapper's attorney Lance Lazzaro said his client was "very happy."

Rapper Tekashi 6ix9ine, whose real name is Daniel Hernandez, leaves after his arraignment on assault charges at the Harris County Courthouse on August 22, 2018 in Houston, Texas. Bob Levey / Getty Images

"Considering today's challenging circumstances as a result of the Covid 19 pandemic, inmates are especially vulnerable to contracting the virus," Lazzaro said. "The Court showed great compassion today and my client is very grateful."

Last week, the judge said he would have sentenced the 23-year-old performer, whose real name is Daniel Hernandez, to home confinement rather than prison when he announced the sentence in December had he known then of the coronavirus.

Engelmayer ordered the release the same day that he asked lawyers to advise what should be done after a former associate of Tekashi 6ix9ine who was released from jail because of the coronavirus threat might have put himself in danger outside bars.

The judge said a video of Kintea McKenzie, who pleaded guilty in the case and was awaiting sentencing, "appears to reflect Mr. McKenzie partying in very close proximity to numerous others."

Engelmayer said he was concerned because the activity might reflect a violation of McKenzie's terms of pre-sentence release and because "the conduct depicted on the video suggests a complete lack of concern by Mr. McKenzie for avoidance of contagion of himself and others."

For Tekashi 6ix9ine, testimony against members of the Nine Trey Gangsta Bloods gang earned him leniency from charges that could have subjected him to a mandatory minimum 37 years in prison for crimes that included orchestrating a shooting in which an innocent bystander was wounded.

The rapper is serving his sentence in a private jail because he cooperated with prosecutors and because the government has control of him as a cooperator.

He was expected to be released July 31. He will be subject to electronic monitoring until he is released from home confinement. Until then, he can visit only his lawyer or a doctor. His lawyer said he was diagnosed in October with bronchitis and sinusitis.

In 2018, Tekashi 6ix9ine had a multiplatinum hit song, "Fefe," with Nicki Minaj, which peaked at No. 3 on the pop charts, and "Stoopid," featuring imprisoned rapper Bobby Shmurda.