(Adds details, background)
BRASILIA, July 3 (Reuters) - Brazil's trade surplus fell less than expected and remained near an all-time high in June, government data showed on Monday, as strong sales of agricultural goods, oil and automobiles helped the economy exit a deep recession.
Brazil posted a trade surplus of $7.195 billion last month, the second largest on record and the biggest ever for the month of June.
Exports totaled $19.788 billion and imports $12.593 billion.
Economists in a Reuters poll predicted a surplus of $7 billion, according to the median forecast, following a record-high surplus of $7.661 billion in May.
Brazil's growing trade surplus has helped keep a steady flow of dollars coming into the recession-hit country, limiting currency losses amid an escalating political crisis.
Economists expect an all-time-high trade surplus of $58.75 billion this year, up from $47.7 billion in 2016, according to a survey released earlier Monday. The central bank forecasts a trade surplus of $54 billion.
Brazil had a trade surplus of $36.219 billion between January and June, also a record for the period. (Reporting by Silvio Cascione; Editing by Andrew Hay and Jeffrey Benkoe)