(Adds Treasury secretary comments)
By Jamie McGeever and Marcela Ayres
BRASILIA, Nov 28 (Reuters) - Brazil's public finances improved in October, Treasury figures showed on Thursday, as a seasonally expected monthly surplus helped reduce the government's overall deficit this year and keep it on track to come in below target.
Still, the 8.7 billion reais ($2.1 billion) primary budget surplus in October was less than economists had expected and social security spending continued to rise, highlighting the underlying strains on the public accounts.
Treasury Secretary Mansueto Almeida said there will be hardly any flexibility in the budget for the next two years, adding that public investment, already its lowest on record, will more likely fall further than rise.
"Don't think that we will have much room for public investment in 2020 or 2021. Under our current rules, the trend for this spending in 2021 is that it will be lower than it is now," Almeida told reporters in Brasilia.
Almeida also said the government is on track to post a nominal deficit this year of around 6% of gross domestic product and register an increase in gross public debt far lower than anticipated.
Almeida was speaking after Treasury figures showed the central government's primary budget surplus in October was less than the 10.7 billion reais surplus median forecast in a Reuters poll, and 11.0% smaller than the 9.5 billion reais surplus posted in the same month last year.
October tends to be a surplus month, thanks to the inflow of oil-related funds and corporate and income tax intakes.
The year-to-date primary deficit, before interest payments are taken into account, narrowed to 63.85 billion reais, 14.8% less in real terms compared with the first ten months of last year, Treasury said.
In the 12 months to October the primary deficit stood at 113.1 billion reais, or 1.1% of gross domestic product, down from 1.3% of GDP a year ago. The government's 2019 target is for a deficit of 139 billion reais.
But social security spending rose 8.0% on the same month a year ago to 14.6 billion reais. That swelled the accumulated social security deficit so far this year to 179.9 billion reais, some 3% wider than a year ago, Treasury figures showed.
($1 = 4.22 reais) (Reporting by Marcela Ayres; Writing by Jamie McGeever; Editing by Marguerita Choy and Nick Zieminski)