BRASILIA, Jan 29 (Reuters) - Brazil’s government posted a fiscal deficit in December that was nearly twice the size of its November deficit, underscoring the challenge facing President Jair Bolsonaro as he tries to balance the federal budget.

The central government, which includes federal ministries, the social security system and the central bank, posted a deficit of 31.784 billion reais ($8.5 billion) before interest payments, nearly twice November’s 16.206 billion reais deficit.

That was well below the government’s target for a deficit of 159 billion reais, but it was the fifth consecutive annual primary deficit, the worst run on record.

Once again, social security was by far the biggest contributor. Although the deficit narrowed slightly in December from the same month a year earlier, it widened by 7 percent to 195.2 billion reais over the course of 2018 from 182.45 billion in 2017.

The social security deficit has been widening since 2015. Halting and reversing this trend will be the new government’s biggest and most important challenge for Brazil’s economy and markets, analysts say.

“Every analyst says, and all the studies show: if Brazil doesn’t reform social security, fiscal adjustment in this country will be impossible,” Secretary of the Treasury Mansueto Almeida told reporters on Tuesday.

Funding the pensions deficit has diverted money from social spending and public investment, Brazil’s Treasury said.

Earlier this month Economy Minister Paulo Guedes told Reuters that pension reform could save up to 1.3 trillion reais over the next 10 years, and one ministry source said Congress could approve a package by the middle of this year.

While the social security deficit continued to widen, the Treasury and central bank’s balance continued to improve. This surplus doubled in December from the same month a year earlier to 22.9 billion reais, and the 2018 surplus widened 29 percent to 74.9 billion reais from 58.2 billion the previous year.