(Adds data on overall budget deficit, background)
By Silvio Cascione and Luciana Otoni
BRASILIA, March 28 (Reuters) - Brazil avoided a primary budget deficit in February, contrary to most market expectations, a small step forward in its efforts to shore up public finances and regain credibility with investors.
Brazil posted a primary surplus of 2.13 billion reais ($938 million) in February, the central bank said on Friday, defying forecasts for a 500 million reais deficit in a Reuters poll with 16 analysts.
The primary budget balance represents the public sector's excess revenue over expenditures before debt payments.
February's unexpected surplus was entirely due to excess savings in states and municipalities. Brazil's central government, which includes the federal administration, social security and the central bank, had a 3.4 billion reais deficit last month, Brazil's Treasury said on Thursday.
Brazil's public finances have deteriorated rapidly under President Dilma Rousseff, leading Standard & Poor's to downgrade the country's sovereign debt rating closer to junk status on Monday.
Brazil's government pledged to save 99 billion reais this year in primary surplus, or 1.9 percent of the country's GDP. But economists in a Reuters poll last month said that target was probably out of reach.
In the 12 months through February, Brazil's primary surplus was equivalent to 1.76 percent of GDP, up from 1.66 percent in January but still below the government's target.
The government has fallen short of its consolidated primary surplus target in the past two years.
Brazil's overall budget deficit, which includes interest payments, narrowed to 9.516 billion reais in February from 10.478 billion in January.
The public sector's net debt was equivalent to 33.7 percent of GDP in February, up from 33.1 percent of GDP in January.
$1 = 2.27 Brazilian reais Reporting by Silvio Cascione and Luciana Otoni; Editing by Meredith Mazzilli