The government ran the first July budget surplus in more than a decade last month, as Britain’s public finances recorded an unexpected leap back into the black with help from an increase in self-assessed tax payments.

Public sector net borrowing last month, excluding the nationalised banks, was in surplus by £184m, the first surplus in that month since 2002, the Office for National Statistics (ONS) said on Tuesday. City economists had expected the government to record a £1bn deficit.

Receipts from self-assessed income tax increased by £800m to £8bn last month, compared with July 2016, giving the government the highest level of July self-assessed tax receipts since it started recording these payments in 1999.

Howard Archer, chief economic adviser at EY Item Club, said the figures were a welcome boost for the chancellor, Philip Hammond, who now had a “very decent chance” of undershooting his 2017-18 fiscal target.

“While a struggling economy and higher interest debt payments look likely to hamper the public finances over the coming months, the chancellor does look to have a very good chance of having some wiggle room in November’s budget,” he said.

However, analysts at Capital Economics expected the improvement on last year to be a “temporary blip”.