(Recast, adds data details and context)
By Alonso Soto
BRASILIA, Sept 30 (Reuters) - Brazil's primary budget deficit in August was half what markets expected, in a brief reprieve for President Dilma Rousseff who is struggling to rebalance public accounts and regain investors' trust.
Brazil posted a primary budget deficit of 7.310 billion Brazilian reais ($1.83 billion) in August, well below the gap of 14.45 billion reais expected by analysts surveyed by Reuters. The commodities' powerhouse had a deficit of 10.01 billion in July.
A drop in public expenditures, mostly on unemployment benefits, helps explains the smaller primary deficit in August but the country's fiscal accounts remain in disarray after years of heavy spending and hefty tax cuts.
Rousseff's inability to shore up the country's finances after losing control over her alliance in Congress has hit investors' confidence, driving down the real to its weakest ever and raising borrowing costs.
So far this year the government has accumulated a primary deficit of 1.1 billion reais or the equivalent of 0.03 percent of the gross domestic product. The government set a 2015 surplus goal of 0.15 percent of GDP.
The central bank and national treasury have had to intervene in markets to tame currency volatility that threatens Brazilian companies already struggling after three years of lackluster growth.
Rousseff's political strength will be tested yet again later on Wednesday when Congress decides on key vetoes that would prevent a surge in public spending in coming years.
Even if lawmakers uphold her vetoes, analysts believe she is unlikely to convince congressional allies to support tax increases and spending cuts needed to avoid an expected primary deficit next year.
The ongoing political crisis stoked by a massive corruption investigation involving her Workers' Party and other allies, combined with a deepening recession, led Standard & Poor's to strip Brazil of its investment-grade rating earlier this month.
Policymakers are racing to prevent other agencies from downgrading Brazil to avoid capital flight.
In the 12 months through August, the primary budget deficit narrowed to an equivalent to 0.76 percent of gross domestic product from 0.89 percent in the year ended in July. ($1 = 3.9837 Brazilian reais) (Additional reporting by Marcela Ayres; Editing by Jeffrey Benkoe and Christian Plumb)