He was leaving a motorcycle dealership in south Florida on Monday when an armed suspect shot him.
Police in Broward County said XXXTentacion, whose real name is Jahseh Onfroy, was taken to hospital where he was pronounced dead.
He was often described as one of rap's most controversial artists and was facing domestic violence charges.
The polarising rapper, who first found an audience by uploading songs to the website SoundCloud, had been hailed as a breakthrough talent and tributes have been pouring in from hip-hop luminaries in the wake of his death.
The county sheriff's office said that Onfroy was leaving the dealership shortly before 16:00 local time when two armed suspects approached.
At least one of them shot him before both fled the scene in Deerfield Beach, which is 43 miles (69km) north of Miami, in a dark-coloured SUV.
Investigators said it appeared to be a "possible robbery". Video posted on social media apparently showed Onfroy slumped in his car.
A witness told celebrity news website TMZ that multiple shots rang out outside the dealership.
The rapper, whose hit songs include SAD! and Moonlight, quickly rose to prominence following the release of his debut album 17 last August.
His follow-up ? debuted at the top of the Billboard 200 chart in March and has been listened to hundreds of millions of times online.
The album tackled subjects such as depression and was praised by some of rap's most high-profile stars.
But his short career was plagued by allegations of domestic violence. He was facing 15 felony charges at the time of his death, including aggravated battery of a pregnant woman.
More about: rapper