UK public borrowing last month was almost a fifth lower than a year earlier, when the economy was feeling the full force of the coronavirus pandemic, but rising inflation put upward pressure on debt costs.
Public sector net borrowing, excluding public sector banks, fell to £22.8 billion in June, still the second-highest June figure on record.
Economists polled by Reuters had forecast a drop to £21.6 billion.
Reflecting the surge in borrowing by British finance minister Rishi Sunak to soften the hit from the pandemic, the data showed Britain's budget deficit leapt to 14.2% of gross domestic product during the financial year to the end of March 2021, its highest share of GDP since World War Two.
"We still expect borrowing to undershoot the OBR's latest forecast for this year. But we are not out of the woods yet, with the recent surge in Covid-19 cases putting some parts of the economy at risk of further restrictions later in the year," KPMG economist Michal Stelmach said.
The Institute for Fiscal Studies, a think tank, said in a report with economists from Citi that borrowing in the 2021/22 financial year would drop to 9.3% of GDP.
This is £30 billion less than the uk government's forecasters expected in March but would still be the third-highest on record.
The Office for National Statistics said June's debt servicing costs - which include an inflation uplift to index-linked gilts' future redemption values as well as actual interest payments - rose to a record £8.7 billion.
A rise in the rate of retail price inflation was largely to blame, it added.
However, debt servicing costs as a share of GDP remain low by historic standards, and most economists say the pace of economic recovery will be the key factor in improving the public finances.
"The economy can do more of the job in 'fixing' the public finances than a fiscal tightening," Ruth Gregory of Capital Economics said.
Public borrowing for the first three months of the financial year totalled £69.5 billion, down more than 40% from the three months to June 2020, when Britain recorded its heaviest-ever borrowing in cash terms due to its Covid spending surge.
But public debt as a share of GDP, excluding public sector banks, was £2.218 trillion or 99.7% of GDP in June, its highest since March 1961.
"It's right that we ensure debt remains under control in the medium term, and that's why I made some tough choices at the last budget to put the public finances on a sustainable path," finance minister Rishi Sunak said.
Sunak's support for laid off workers and a tax break on property purchases are being phased out, while a temporary increase in the main benefit for the unemployed and low-earners will stop on October 1. Overseas aid spending has also been cut.
Sunak is due to hold a review of government spending before the end of the year.
The IFS think tank said that although the short-run outlook for the public finances was better than in March - giving scope for one-off giveaways - the long-term prospects pointed to spending cuts for some government ministries unless taxes rise.