A 22-year-old man has been charged with murdering US rapper XXXTentacion who was shot in his car in Florida.

Dedrick Williams, of Pompano Beach, was arrested shortly before 7pm on Wednesday, the Broward Sheriff’s Office said.

Jahseh Dwayne Onfroy, 20, who went by the stage name pronounced Ex Ex Ex ten-ta-see-yawn, was shot dead on Monday, bringing a violent end to a brief music career that was marked by controversy and arrests.

Authorities said the rapper was ambushed by two suspects. They did not give a motive in announcing Williams’s arrest but previously said the shooting was an apparent robbery attempt.

XXXTentacion’s lawyer David Bogenschutz said on Tuesday that investigators told him the rapper had visited a bank shortly before the shooting and possibly withdrew cash to buy a motorcycle at Riva Motorsports in Deerfield Beach.

Williams is charged with first-degree murder without premeditation, a probation violation and not having a valid driver’s licence.

Court records show Williams has been charged previously with several felonies, including grand theft auto, domestic violence, cocaine possession and possession of a firearm by a convicted felon.

XXXTentacion, who sported dreadlocks and facial tattoos, was a rising star. He notched a number one album in March with “?” and had a top 10 hit with “Sad!”.

But he also generated controversy. In 2016, he was arrested on charges including home invasion for a 2015 incident, and less than a month later was jailed on charges that he attacked his girlfriend, who was pregnant at the time. Later, he faced more charges including witness tampering.

In a recent interview with the Miami New Times, XXXTentacion described his upbringing, which included seeing his mother infrequently and being raised by friends, family and baby-sitters. His mother bought him clothes, phones and other gifts. He said he used violence so she would engage with him.