The accused American rapper Cardi B has pleaded guilty to assault and grossly negligent endangerment of third parties.

In doing so, she avoided a trial in a New York court, which would have threatened her with imprisonment if she was convicted.

The 29-year-old musician, whose real name is Belcalis Almanzar, must now do 15 days of community service, as reported by American media.

According to the indictment, there was a physical argument between the rapper and two barmaids in a strip club in New York in August 2018.

Cardi B and her companion are said to have thrown bottles, drinks and chairs at the women.

The two alleged victims stated at the time that they had been injured.

Cardi B initially denied the allegations in 2019.

She's made some "bad decisions" in the past, but now she's more mature and wants to act "responsibly," the rapper said in a statement, according to TMZ.

Queens District Attorney Melinda Katz welcomed the guilty plea.

"No one is above the law," Katz wrote on Twitter.

Cardi B has been married to rapper Offset since 2017 and they have two children together.