Sweden's Prime Minister has rejected U.S. President Donald Trump's call to free incarcerated rapper A$AP Rocky.

The Fashion Killa hitmaker, real name Rakim Mayers, was charged with assault by Swedish prosecutors on Thursday, after spending more than three weeks in custody in the Scandinavian nation.

His detention has sparked an outcry in the U.S. and, after Rocky was charged, President Trump demanded his release on Twitter.

However, a spokesperson for the Swedish government rebuffed Trump's call on Friday, asserting the independence of their legal system.

"Sweden and Prime Minister Stefan Lofven have been very clear in the dialogue with both the White House and directly with the American president, that in Sweden everyone is equal before the law and that the government cannot interfere in legal proceedings," the official told Reuters.

Rocky's case has proved controversial as he was held in custody for three weeks before being charged, and celebrities including Kim Kardashian and Kanye West had lobbied Trump to take up the cause. The President spoke to Swedish Prime Minister Stefan Lofven last weekend, and on Thursday issued his threatening tweets demanding the 30-year-old musician be freed.

"Very disappointed in Prime Minister Stefan Lofven for being unable to act," the President wrote. "Sweden has let our African American Community down in the United States. I watched the tapes of A$AP Rocky, and he was being followed and harassed by troublemakers. Treat Americans fairly! #FreeRocky."

He later added: "Give A$AP Rocky his FREEDOM. We do so much for Sweden but it doesn't seem to work the other way around. Sweden should focus on its real crime problem! #FreeRocky."

Rocky's arrest on 2 July came two days after he and his entourage were involved in a street brawl after performing at a Swedish festival. He claims he and two companions, who have also been charged with assault, were acting in self-defence. If convicted, they could face up to two years in prison.