MSPs have voted to keep the European flag flying daily outside the parliament building even after the UK leaves the EU on Friday.
Holyrood backed the move on Wednesday by 63 to 54, with SNP MSPs joined by the Scottish Greens in endorsing it.
The vote was called this week in response to a decision by the Scottish Parliament’s Corporate Body (SPCB) to remove the flag after Brexit takes place at 11pm on January 31.
But opposition MSPs were angered by the decision to hold a debate on the issue, saying it was a waste of parliamentary time.
The vote on the matter is binding.
It is the first time parliament has overturned a decision of the SPCB and directed it in this way.
Beginning what was a stormy debate, culture secretary Fiona Hyslop said: “We need to give practical demonstration to the sense of loss that so many in this chamber and beyond will feel when we are no longer members of the European Union.”
She said the vote gives the Scottish Parliament a choice on the issue, adding the SPCB’s decision to remove the flag “does not reflect the views of parliament as a whole”.
During her speech, Hyslop repeatedly rejected an intervention from Labour MSP Neil Findlay, which he could be heard describing as “a disgrace”.
Findlay raised a point of order with deputy presiding officer Linda Fabiani, complaining backbenchers were not due to speak in the debate and so should be allowed to interject.
Fabiani stepped in to chide MSPs for being “rude” in the chamber.
Scottish Tory MSP Liz Smith said the passing of the motion would set a dangerous precedent of the Government overruling the SPCB – which is supposed to remain neutral.
She said: “It is vital that there is full trust and confidence in the work of the corporate body to act in an impartial manner on behalf of all members, rather than on behalf of the political parties of the Parliament.
“The issue before this Parliament today is not what we think about the withdrawal of the UK from the EU, it’s about whether members of this Parliament are prepared to undermine the corporate body.
“Are we well aware of the dangers that could provide?”
Later in the debate, tempers flared between Scottish Green MSP Ross Greer, Tory justice spokesman Liam Kerr and Liberal Democrat MSP Liam McArthur.
After announcing his support for the motion, Greer took an intervention from Kerr in which the Tory claimed his request for a ministerial statement on the state of the police estate in Scotland had been refused due to “lack of time”.
Kerr asked the Green MSP if he feels “any shame or embarrassment” for supporting such a debate going ahead.
Greer responded: “I’m sure Mr Kerr enjoyed that moment of self-indulgence but I’m going to come to the point of the hypocrisy of the Tories in a moment.”
The Green MSP also chastised the Liberal Democrats, who had indicated before McArthur spoke that they would not support the government motion.
He said: “The only real losers here are the Liberal Democrats – the party of Europe – who, unless they’re about to make some significant U-turn, are set to vote with the Conservatives to take the flag down.”
In response, McArthur said: “It’s a matter of deep regret to me that this parliament is having this debate on this government motion and has just been subjected to that contribution from Ross Greer.”
Announcing the motion had been passed later at decision time, presiding officer Ken Macintosh said: “The parliament has resolved to direct the SPCB to continue to fly the European flag daily from Holyrood, and I can confirm the SPCB will amend its flag flying policy with immediate effect.”