The Brazil forward received around €14m of the bonus before leaving Barca, who deposited the remaining amount with a notary once it became evident he was signing for Paris Saint-Germain.
When he signed for PSG in a world record €222m deal in 2017, he demanded Barca pay the rest of the bonus. Barca, represented by Costa-Torrecillas-McCragh, responded by suing him for breach of contract and requested the return of the €14m already paid to Neymar as well as €8.5m in damages plus interest.
On Friday a judge sided with Barca, with ESPN having access to the full ruling, which states that Neymar was in breach of his contract as he terminated it prematurely without just cause "beyond his mere will" to sign for another club when PSG paid his release clause.
Neymar reserves the right to appeal the decision and has 10 days to do so. If he does choose to appeal, sources close to the case say a final resolution is not expected until, at the earliest, the end of July.
"We express our satisfaction with the verdict announced today by Social Court 15 in Barcelona in relation to the lawsuit involving FC Barcelona and the player Neymar Jr regarding the amount of the signing bonus in the final renewal of the player's contract," Barca said in a statement.
"The ruling has fully dismissed the player's claim for payment of €43.6m, and has accepted a large part of the defence presented by FC Barcelona, as a result of which the player must return €6.7m to the club.
"Since the player's representative is entitled to appeal this decision, the club shall continue to fervently defend its legitimate interests."
A source at Barca told ESPN they did not expect the judge to side in the club's favour and that they had made plans to have to pay the rest of the bonus.
Barca have unsuccessfully tried to bring Neymar back to the club over the last two years despite the ongoing battle with the Brazilian in the courtroom.
With Neymar also keen to return to Camp Nou, there were talks last year to settle the disagreement out of court. However, despite willing on both sides, they were unable to come to an understanding, leaving the final decision in the hands of the court.
Neymar, 28, joined Barcelona in 2013 and signed a five-year contract extension with the club in 2016, linking him to Camp Nou until 2021.
However, less than a year after signing that deal, he left for French champions PSG, who paid his €222m release clause.
During four seasons with Barca, Neymar made 186 appearances and scored 105 goals, forming an electric front three with Lionel Messi and Luis Suarez. Together they won two leagues titles, three Copas del Rey and the Champions League in 2015.
After trying and failing to bring Neymar back last summer, despite a number of meetings with PSG, Barca were preparing another offensive for this year. But with the financial implications of the coronavirus pandemic, it's extremely unlikely they will be able to complete a deal to re-sign him.
The club are focusing on other targets, such as Inter Milan striker Lautaro Martinez, and sources have told ESPN they will only be able to spend on signings what they make in player sales.