The high court in Madrid has rejected a request from Switzerland to remand in custody a whistleblower who leaked bank details of HSBC clients to authorities.

Hervé Falciani was detained in Spain on Wednesday but has been released pending the outcome of an extradition request.

Mr Falciani is not permitted to leave Spain ahead of the court's decision.

In 2015 the French national was sentenced in Switzerland to five years in jail for industrial espionage over the leaking of secret bank data.

On Thursday, the court in Madrid ordered Mr Falciani to hand over his passport and said he must appear before them every week while it considers the Swiss extradition request.

Mr Falciani's lawyer, Manuel Olle, said the court's measures to keep his client in the country were "quite drastic".

An earlier extradition request from Switzerland prompted Mr Falciani's arrest in Barcelona in 2012. But in 2013 Spain's High Court rejected the request, arguing that the accusations were not offences in Spain.

Mr Falciani, who had worked in the IT department at HSBC's Swiss private banking unit, fled to France from Geneva in 2009.

He said he wanted to expose massive tax evasion via Swiss accounts. Swiss authorities say Mr Falciani stole and attempted to sell confidential data, violating Swiss banking secrecy laws.

Spanish police sources say they received a Swiss international arrest warrant on 19 March.

While Mr Falciani usually lives in France, which rarely extradites its own citizens, he was on his way to address a conference on whistleblowing in Madrid when he was detained.

Last November, HSBC agreed to pay €300m ($368m; £262m) to French authorities to settle a long-running investigation into tax evasion by French clients via Switzerland.

A team at the International Consortium of Investigative Journalists (ICIJ), led by France's Le Monde daily, published Mr Falciani's "Swiss Leaks" data, revealing accounts held by more than 100,000 wealthy individuals and legal entities.

The ICIJ said the accounts - belonging to HSBC clients from 203 countries - contained more than $100bn in total.

HSBC says it has tightened up its compliance mechanisms since the violations came to light.