Federal prosecutors in Miami on Wednesday successfully appealed a judge's decision to release rapper Kodak Black on bond after his arrest for a weapons violation.

In a hearing in U.S. District Court, Judge Federico Moreno said the 21-year-old rapper was a "danger to the community" based on his lengthy criminal record.

Black was arrested during a Miami-area hip-hop festival earlier this month that was marred by several violent incidents outside the venue. Authorities are investigating three unrelated shootings in the Miami area with possible connections to the festival.

RAPPER KODAK BLACK ARRESTED, LIL WAYNE SEARCHED BY POLICE AT MIAMI HIP-HOP FESTIVAL

Prosecutors say that on two occasions Black had falsified information on federal forms to purchase firearms from a Miami-area gun shop. Black purchased a 9 mm handgun, a .380-caliber handgun and a semiautomatic Mini Draco weapon, according to Assistant U.S. Attorney Bruce Brown.

The rapper pleaded not guilty, and a judge previously granted his release on $550,000 bond and house arrest. Moreno overturned that decision, saying the type of weapons purchased by Black was concerning. The judge suggested it was unlikely Black could remain out of trouble even if placed under supervised house arrest.

RAPPER KODAK BLACK ARRESTED AT BORDER IN UPSTATE NEW YORK

When asked about why Black needed firearms, his attorney, Branford Cohen, responded that the rapper faced security threats from gangs and other rivals.

Authorities said one of the weapons purchased by Black was found at the scene of a recent shooting in nearby Pompano Beach.

The rapper also faces drug, weapons and sexual assault charges in other states. He will be held in custody in Miami while he awaits a trial date likely to be scheduled before the end of the summer.

CLICK HERE TO GET THE FOX NEWS APP

Prosecutors said Black could face up to eight years in prison if convicted.