A judge in Brazil has ordered the release of Diego Dzodan, the vice-president for Latin America of the social media company Facebook.
Mr Dzodan was arrested on Tuesday for refusing to share with police WhatsApp messages sent by alleged drug dealers.
Facebook owns the messaging service WhatsApp, but Facebook says the service operates separately.
Judge Ruy Pinheiro said the decision to arrest Mr Dzodan had been “extreme” and called it “unlawful coercion”.
“It seems to me that the extreme measure of imprisonment was hurried,” he said when he overturned Tuesday’s decision by a judge in a lower court.
The judge who had ordered Mr Dzodan’s arrest had accused the executive of “repeated non-compliance of court orders” for not sharing the WhatsApp messages.
Police argued that “this information was required to produce evidence to be used in an organized crime and drug trafficking investigation.”
But a source told the BBC that the Facebook office in Brazil dealt only in sales and said that no-one there had access to WhatsApp user information or the authority to make decisions on behalf of the messaging app.
Facebook said it had “always been and will be available to address any questions Brazilian authorities may have”.
The arrest of Mr Dzodan came only months after a Brazilian court ordered mobile phone companies to block the WhatsApp application for two days because it said WhatsApp had repeatedly failed to co-operate in a criminal investigation.
That order, too, was overturned by a higher judge who said it was “not reasonable that millions of users be affected by the inertia of the company”.
WhatsApp is reported to be the most used application in Brazil, with about 93 million users.