Brazil defender Dani Alves was back in court Monday to testify before the judge investigating a rape allegation made by a woman in Barcelona for which he has been remanded in custody. 

The 39-year-old, who has been remanded in custody since January 20, appeared in court at his own request, giving a brief statement to the judge in which he admitted the pair had sexual relations but said it was consensual, judicial sources said.

The former Barcelona and Paris Saint-German star is under investigation for the alleged crime of sexual assault -- which in the Spanish penal code includes rape.

Police said they received a complaint from a young woman on January 2, with a source close to the investigation confirming Alves was accused of rape.

The incident reportedly took place in the bathroom of a popular Barcelona nightclub in late December. 

The player, who initially denied knowing her, changed his story several times, later saying they had consensual relations, sources close to the case said.

The first time he testified was on the day of his arrest when the judge ordered that he be held in custody without bail given the contradictions in his initial statements and the risk of him absconding.

Alves' defence team filed a motion for his release which was rejected on February 21 with the court saying he posed "a high flight risk".

It cited the potentially heavy sentence he could face, the "serious evidence of criminality" against him and the fact Brazil was unlikely to extradite him for trial.

At the time of the incident, Alves was on holiday in Barcelona after playing for Brazil at the World Cup in Qatar.

After his arrest, Alves was sacked by his Mexican club Pumas UNAM.

In a highly successful career, Alves made 408 appearances for Barcelona, 391 of which were during his first spell with the club between 2008-2016.

During that initial period, he won six La Liga titles, three Champions League crowns and four Copa del Rey trophies.

At the last year's World Cup, he became the oldest player to represent Brazil at football's showpiece tournament.