Image copyright Getty Images

US rapper ASAP Rocky has temporarily been released from custody in Sweden.

The 30-year-old, real name Rakim Mayers, will be freed until a judge returns a verdict in the assault trial on 14 August.

He and two of his entourage have pleaded not guilty to assaulting a 19-year-old man in Stockholm in June.

Over the past week, a court has heard evidence and testimonies about the brawl, which led to ASAP Rocky's detention in the country.

The rapper says he, Bladimir Corniel and David Rispers were acting in self-defence in fighting that broke out near the Max Burger chain on 30 June, after two men allegedly refused to stop following his entourage.

But in court on Friday, the prosecution said ASAP Rocky and his companions had "every possibility" to leave the scene and that they were not in a position where they needed to use "self-defence".

During his summing up, prosecutor Daniel Suneson told the Stockholm District Court the rapper should be jailed for about six months.

ASAP Rocky's defence lawyer, Slobodan Jovicic, argued the incident was not a pre-meditated group assault and the rapper should be set free.

Image copyright Reuters Image caption ASAP Rocky (back right) smiled widely as he left the district court

The Swedish judge, Per Lennerbrant, said the performer and his two co-accused could be released from custody and were free to leave the country ahead of his verdict.

Such a ruling may point to an acquittal, or a sentence of less than the time already served, Reuters reported.

Mr Jovicic said his client "is a free person for now" but has a "nervous wait for two more weeks".

How is Donald Trump involved?

The case has made waves internationally, with an online petition for the rapper's release garnering more than 640,000 signatures.

US President Donald Trump was among those to back a #JusticeForRocky campaign that attracted the support of celebrities such as Kanye West and Justin Bieber.

The US president even sent his special envoy on hostage affairs - Robert O'Brien - to Sweden to attend the trial.

On Friday, Mr Trump claimed ASAP Rocky was "on his way home to the United States" in a tweet posted shortly after the ruling to temporarily free the rapper.

Mr O'Brien told reporters he had called the president to tell him the rapper "would be back in America soon", but did not elaborate on the timescale.

What does the rapper say happened?

Earlier this week, ASAP Rocky said that he and his team had felt threatened by the people they clashed with and said he is not looking for money but wants justice and for his name to be cleared.

Much of the trial has centred around analysing videos and whether bottles had been used as weapons during the alleged assault.

The rapper did not deny he was holding a glass bottle in his hand - but says he picked it up briefly before putting it back down.

Warning: There are images below showing bloody injuries to a person's body, which you may find upsetting

The prosecution claimed a bottle was used in the fight, but the US star insisted he did not use it to hurt the alleged victim.

On Friday, ASAP Rocky's bodyguard said the teenager had been "harassing" and "following" the group and "swung" at him prior to the brawl.

After being released the rapper said it had been a "difficult and humbling experience" in a post on Insatgram.

What of the victim?

The court also heard from a psychologist, who told the court the alleged victim is not sleeping at night, has lost concentration, and is afraid.

Image copyright Maddy Savage Image caption Fans of ASAP Rocky have been gathering at the court in Stockholm all week, shouting chants such as 'Free Rocky'

Earlier this week, the prosecution went through a detailed 522-page preliminary report, which contained extensive photographs of injuries the alleged victim suffered.

The man, who is not being named by media, has claimed damages of roughly £12,000 (139,700 Swedish Krona).

During his evidence, he told the court he was looking for a friend and first approached the rapper and his entourage to ask "if they knew where his mate was".

When asked by ASAP Rocky's lawyer if he knew the rapper was famous he said: "Honestly not."

Image copyright Swedish Police Image caption Injuries on the alleged victim's body - which prosecutors claim are consistent with use of a bottle

Fans of ASAP Rocky have been attending court

Image copyright Alamy Image caption Fans Arvin Flod and his friend Martyna Lechowska have turned up at the court in Stockholm

Fans of the rapper have been gathering at court in Sweden in growing numbers over the week.

Patrick, 16, says he wants to "seek justice" and thinks the rapper has "lots of energy" and "good vibes".

He says the case could have a negative impact on Sweden in the future because he believes "other rappers won't come and do gigs".

20-year-old Arvin Flod says the case is the "biggest thing in Sweden right now", while his friend Martyna Lechowska, 20, doesn't think he should have "locked in for such a long time" already.

If found guilty, the men on trial could face up to two years behind bars.

Follow Newsbeat on Instagram, Facebook, Twitter and YouTube.

Listen to Newsbeat live at 12:45 and 17:45 weekdays - or listen back here.