(Adds federal tax and overall budget deficit figures, analyst comment)
By Alonso Soto and Marcela Ayres
BRASILIA, Aug 28 (Reuters) - Brazil's primary budget deficit widened more than expected in July, central bank data showed on Friday, threatening government efforts to eke out at least a small surplus this year to fend off a debt-rating downgrade.
Brazil posted a public sector primary budget deficit of 10.02 billion reais ($2.81 billion) in July, well above market estimates for a gap of 7.2 billion reais and the third straight monthly deficit. It was the biggest deficit for a month of July on record.
Wall Street ratings agencies and bondholders closely watch the gauge since it measures how much current government revenue is available to pay interest on the debt.
The overall budget deficit, including interest payments, was 72.77 billion reais ($23.4 billion) in July. That took the 12-month overall budget deficit to 502.8 billion reais ($140.8 billion), or 8.81 percent of gross domestic product, the deepest shortfall in at least 13 years.
"We have yet to detect a visible turnaround in the fiscal picture," said Alberto Ramos, an economist with Goldman Sachs in new York. "A deep, permanent, structural fiscal adjustment remains front-and-center on the policy agenda to restore both domestic and external balance."
Rebalancing the public accounts after years of heavy spending is a priority for President Dilma Rousseff as she scrambles to avoid losing Brazil's investment-grade rating.
With the economy contracting rapidly in what appears to be the worst recession in decades Rousseff faces an uphill battle.
The Brazilian economy shrank 1.9 percent in the second quarter compared with the first quarter, sinking into recession after two quarters of consecutive contractions. Many economists believe Brazil will not see signs of a recovery until well into 2016.
The shaper downturn has dragged down tax revenues, which so far this year have dropped 2.91 percent in inflation-adjusted terms.
To show greater commitment to austerity, the government plans deeper spending cuts in the 2016 budget bill on top of promises to reduce the number of Cabinet ministries and sell properties.
In the 12 months through July, the primary budget deficit widened to an equivalent to 0.89 percent of GDP from 0.80 percent in the year ended in June.
In July, the government cut its primary budget surplus goal for this year to 8.7 billion reais, or 0.15 percent of GDP, from 66.3 billion reais, the equivalent of 1.1 percent of GDP, originally budgeted. ($1 = 3.57 Brazilian reais) (Editing by W Simon)