(Adds historical comparisons, deficit-to-GDP ratios)
BRASILIA, July 25 (Reuters) - Brazil posted a current account deficit of $3.345 billion in June, a smaller-than-expected gap that was fully offset by foreign direct investment inflows for the first time since November, central bank data showed on Friday.
The country had been expected to post a deficit of $3.9 billion, according to the median forecast of 19 analysts in a Reuters poll. Brazil's current account deficit in May was $6.635 billion.
The current account is a country's widest measurement of foreign exchange flows, including trade, services, interest payments and remittances.
Foreign direct investment -- which falls into Brazil's balance of payments' capital account -- was $3.924 billion in June, in line with market expectations of $3.925 billion.
The last time that FDI at least covered the current account deficit was in November of 2013.
The country's current account gap has widened sharply over the last two years due to a dwindling trade surplus that had its weakest result in a decade in 2013.
The current account gap as percentage of GDP dropped slightly to 3.58 percent in June from 3.61 percent the previous month. (Reporting by Alonso Soto; Editing by Meredith Mazzilli and W Simon)