(Adds reasons for wider deficit, bank official comment)
BRASILIA, July 26 (Reuters) - Brazil's current account deficit came in much larger than expected for June as a stronger real reduced the gains of local exporters, central bank data showed on Tuesday.
The commodity-exporting nation recorded a currency account gap of $2.479 billion, a bigger shortfall than the $1.5 billion expected by economists in a Reuters poll.
The country attracted $3.917 billion in foreign direct investment in June, below forecasts of $4 billion in a Reuters poll.
Brazil posted a current account surplus of $1.2 billion for May and a deficit of $2.563 billion for June 2015.
The nation's trade surplus shrank to $3.970 billion from $4.530 billion a year earlier.
The real strengthened more than 12 percent against the U.S. dollar in June alone.
"Since February we have had an appreciation of the exchange rate, and that, without a doubt, has an effect on the external results," said Tulio Maciel, the central bank's head of economic research.
Maciel said the bank forecast a current account deficit of $4.3 billion in July.
He added that the monthlong Olympics, that start in August in Rio de Janeiro, could add an additional $200 million in local travel expenditures.
A sharp appreciation of the Brazilian real has raised fears that the gains in exports could be short-lived in a country struggling with its worst recession in decades.
Government officials have said a real above 3 per dollar is needed to keep Brazilian exporters competitive after years of struggling with an expensive currency that raises their production costs. (Reporting by Marcela Ayres; Writing by Alonso Soto; Editing by Jeffrey Benkoe and Lisa Von Ahn)