Ecclestone, 91, had been in the country with his Brazilian-born wife, Fabiana, who was elected an FIA vice-president last year.
He has previously said that he was shaken by the abduction of his mother-in-law in Sao Paolo six years ago.
Kidnappers demanded a ransom of $36.5m (£28m) for her safe release, but she was freed unharmed after a police operation.
Ecclestone was arrested on Wednesday evening when his luggage was being screened ahead of his flight, according to a police statement quoted by Reuters.
Officers found an undocumented LW Seecamp .32 gun in his luggage and took him to a facility at Viracopos airport, close to Sao Paolo.
Reports from Brazil suggest that Ecclestone paid R$6,060 (£1,000) to be released on bail after police took account of the circumstances and the risks that come with a fortune estimated at £2.5bn in the latest Sunday Times Rich List.