Government borrowing was £22.9bn last month, the second-highest June borrowing since monthly records began in 1993.
The Office for National Statistics said that borrowing was £4.1bn more in June than the same month a year ago.
It hit £22.9bn over the month as spending rose by £9bn to £86bn, mainly because interest payments increased by £10.3bn compared to this time last year.
Chancellor Nadhim Zahawi said: “We recognise that there are risks to the public finances including from inflation, with debt interest costs in June more than double the previous monthly record.
“That’s why the government has taken action to strengthen the public finances, and in their latest forecast the OBR (Office for Budget Responsibility) assessed that we are on track to get debt down.”