The Scottish government has narrowly won a vote to keep the EU flag flying over the Edinburgh parliament building after Brexit, despite being accused of undermining the impartial status of Holyrood’s governing body.

The result came at the end of a fractious afternoon in the Holyrood chamber, with the Scottish National party government facing heavy criticism for taking up parliamentary time with the flag motion and another debate about independence, which was likewise won by a small margin.

The flag vote, which the SNP secured by nine votes with the support of the Scottish Greens, reversed a previous decision by the Scottish parliamentary corporate body (SPCB) – a management group made up of members of each of Holyrood’s parties – that the flag should be lowered at 23:00 on 31 January, the moment the UK officially leaves the EU. This is the first time that Holyrood has overturned a decision of the governing body in this way.

Opposition members characterised the move as setting a dangerous precedent, interfering with the decision-making of the neutral management group.

But the cabinet secretary for culture, tourism and external affairs, Fiona Hyslop, insisted that continuing to fly the flag was “an opportunity for the Scottish parliament to stand firm in solidarity with the 230,000 EU citizens who live in Scotland”.

Hyslop said it would also give “a practical demonstration” of the sense of loss felt by many Scots at leaving the EU: “At times of uncertainty and disruption, symbols matter.”

The presiding officer, Ken Macintosh – Holyrood’s equivalent of the House of Commons Speaker – had appealed to the Scottish government by letter last week not to make the flag-flying policy a political issue.

Macintosh wrote: “The corporate body recognises entirely the sensitivity that remains over Europe, but its decision is not a political one. Our flags reflect our relationships in law.”

In the chamber on Wednesday, the Scottish Conservatives argued that the SNP should not be wasting parliamentary time debating flags when key public services like education, health and prisons deserved more political attention, with Liz Smith arguing that it set a dangerous precedent to interfere in a body elected “to make decisions on an impartial basis to the collective benefit of all of us”.

Scottish Labour’s Claire Baker added that there was a clear risk of the Scottish parliament beginning to direct and politicise the corporate body, especially if the vote was won by a narrow margin.

“This is the time when we should be focusing on the real challenges facing Scotland as a consequence of that decision, which I don’t believe are encapsulated in a debate about whether to fly a flag.”

Baker added: “What is problematic is the way this debate politicises the decision, undermines the status of the corporate body and questions their ability to act independently of parliament.”

Following the irritable 30-minute debate, the first minister, Nicola Sturgeon, introduced another motion which called on MSPs to back holding a second referendum in 2020.

Sturgeon asked MSPs whether they supported the principle of people having the right to choose and to change their minds. “Given what the Tories have in store, another referendum on independence is not just legitimate,” she said.

Sturgeon, who will set out her next steps on Friday after Boris Johnson rejected her call for the legal powers to hold another referendum was ridiculed by the Scottish Labour leader, Richard Leonard, for wasting Holyrood’s time to “placate an over-agitating political base of activists”.

“The first minister is playing a game. Nobody in this chamber really believes there will be a referendum this year,” he said.

Reflecting growing differences within Scottish Labour on constitutional policy, the party’s former Brexit spokesperson Neil Findlay interjected that he might have backed a “more realistic and rational” motion because he believed in “the sovereign right of the Scottish people”, but added that it made no sense to hold a fresh referendum until the full consequences of Brexit were known.

MSPs previously backed a motion calling for a second referendum in March 2017 by a margin of 69 to 59 but neither that nor Wednesday’s vote can bind the UK government.