(Adds Breakingviews link)
By Alonso Soto
BRASILIA, May 31 (Reuters) - Brazil had a steep primary budget surplus in April, beating market expectations and recovering from a deficit the previous month, but not nearly enough to avert an expected record shortfall this year.
The country posted a public sector primary surplus of 10.182 billion reais ($2.84 billion) in April, central bank data showed on Tuesday, well above market expectations for a surplus of 700 million reais and a March deficit of 10.64 billion reais. The public sector includes the balance of the federal government and states and municipalities.
The primary surplus, or excess revenue prior to interest payments, is a key gauge of a country's capacity to repay its debt.
Interim President Michel Temer, who replaced President Dilma Rousseff this month while she faces an impeachment trial in the Senate, has the daunting task of plugging a massive fiscal deficit.
The bigger-than-expected surplus was due mainly to a steep surplus in the central government accounts, which is the balance of federal entities only. The central government had an increase in the collection of income taxes due in April and fall in expenditures of subsidies because of new government payment guidelines.
Even with the surplus in April, the primary budget deficit in the accumulated previous 12 months rose to the equivalent of 2.33 percent of gross domestic product from 2.28 percent the previous month.
"Fiscal consolidation in Brazil will be a multi-year endeavor," said Alberto Ramos, senior economist with Goldman Sachs. "Most likely, returning to primary fiscal surpluses will take no less than 2-3 years."
Temer, a centrist who has vowed a shift toward more business friendly policies, has proposed constitutional changes to limit public expenditures as a way to rebalance the public accounts.
He set a public sector primary deficit goal of 163.9 billion reais for this year, a record shortfall that many investors say could lead to more public spending ahead of the October mayoral elections.
Some analysts believe his government needs deeper budget cuts this year to improve the fiscal accounts right away.
In the 12 months through April, the overall budget deficit, which includes interest payments, was equivalent to 10.8 percent of GDP. In April, the overall deficit widened to 13.163 billion reais from 9.995 billion reais the previous month.
A recession entering its second year and past fiscal mismanagement has raised fears among investors that Brazil will be unable to repay its debt in coming years. ($1 = 3.5905 Brazilian reais)
Additional reporting by Marcela Ayres, Marcelo Texeira and Silvio Cascione; Editing by W Simon