Police Scotland spent more than £3m covering the costs of Donald Trump’s private visit to Scotland last year, deploying more than 5,500 officers around the country.

The US president spent two nights at his Trump Turnberry resort in Ayrshire, where he played golf and had private meetings after attending a gala dinner at Blenheim Palace, talks with Theresa May in Buckinghamshire and an audience with the Queen at Windsor Castle.

His visit to Turnberry was met by protests at the course and demonstrations in seven Scottish towns and cities, including Edinburgh, and at his other golf course north of Aberdeen. A paraglider paid by the campaign group Greenpeace buzzed Trump while he stood outside his hotel, breaching a no-fly zone.

Police Scotland has disclosed it spent £3.2m above its normal day to day budgets to provide policing for the visit, following a freedom of information request from the Guardian.

The force had to build watchtowers and temporary barriers, as well as perimeter patrols at Turnberry and nearby Prestwick airport, which is used by the Trumps on their visits to Turnberry. It also had to prepare for the possibility that Trump would visit his other golf resort in Aberdeenshire.

Police Scotland said 5,537 personnel had claimed overtime or time off in lieu as a result of being deployed during the visit. Its overtime bill reached nearly £1.6m, included in the £3.2m total.

Several weeks before Trump’s visit, the then acting chief constable of Scotland, Iain Livingstone, said he had to cancel leave and rest days for many officers to ensure he had adequate resources. He forecast the extra costs could hit £5m.

It prompted an appeal from Humza Yousaf, the Scottish justice secretary, to the UK government for financial help, even though policing policy and funding is devolved to the Scottish government.

The Treasury minister, Liz Truss, confirmed the UK government would foot the bill for policing costs directly associated with the visit, in line with its decision to provide extra funding for English forces.

In October, the National Police Chiefs’ Council, the representative body for English and Welsh chief constables, estimated its members spent £18m on policing Trump’s visit.

Calum Steele, the general secretary of the Scottish Police Federation, the union for rank and file officers, said the need to invest that level of resources into the visit reflected Trump’s status, the significant size of the locations he visited and the potential for protests.

He said it was essential the costs were met at UK level. “The president of the United States did not visit the UK to meet the prime minister of England,” he said. “The policing costs were considerable and unless met will leave the service with diminished capacity and capability to deliver policing in Scotland, especially at a time of shrinking budgets.”

Patrick Harvie, the Scottish Green party’s leader at Holyrood, said: “The public will be appalled at the cost we are all paying as a result of the UK government fawning over this bigoted bully. He should never have been invited and Police Scotland should send the bill not to the UK government but to Trump himself as his visit was part business expense part ego trip.”