MSPs have passed legislation devolving Scottish forestry - but stripped back the plans set out by ministers.
The Forestry and Land Management (Scotland) Bill will bring forestry under Holyrood's jurisdiction.
However, opposition MSPs successfully changed the bill to mean it will be overseen by two "arms-length" agencies rather than a government department.
Rural Economy Secretary Fergus Ewing said the passage of the bill was still "an historic occasion" in devolution.
He said ministers would "make every effort" to make the approach demanded by MSPs work, despite having earlier warned them that it was not "the right way forward".
The bill, as amended, ultimately passed unanimously, 120 votes to zero, and will now pass into law once it receives royal assent.
The bill completes the devolution of forestry north of the border, and aimed to replace the Scottish branch of the Forestry Commission with a Holyrood government department.
However after a last-minute campaign from foresters, Labour's Claudia Beamish tabled an amendment for the final debate stipulating that ministers establish "a single agency" rather than a new department.
She said this would be a "lift and shift" of the current Forestry Commission Scotland into a new arms-length agency, thereby "preserving the valuable knowledge and expertise" of existing staff and structures.
Ms Beamish said there were serious misgivings about the centralisation and even possible future privatisation of forestry - although the latter point was strongly refuted by SNP members, who called privatisation a "chimera".
Another Labour MSP, Colin Smyth, added an amendment changing the wording to "an agency or two agencies", and this form of words was subsequently approved by 63 votes to 61.
Among a number of other amendments forced through against the government's wishes, opposition members also united to strip some compulsory purchase powers out of the bill.
Mr Ewing initially told MSPs that a single agency would be "disastrous" and said a two-agency approach "has not been sufficiently scrutinised or tested".
He argued that setting up a forestry department would put the sector "right at the heart of government".
However, he said he was "extremely proud to be the cabinet secretary responsible for this landmark bill", which he said would "modernise" the management and regulation of forestry and make it "fully accountable" to Holyrood.
Mr Ewing said: "It is disappointing that we will now not be able to forge ahead with our planned arrangements but I will absolutely respect and deliver the will of parliament.
"In working out how to deliver what parliament wants, I will do all I can to provide as much pace, clarity and certainty to ensure that the staff working currently in Forestry Commission Scotland and Forest Enterprise Scotland can move swiftly and seamlessly to the new administrative arrangements."
The move was welcomed by opposition members.
Ms Beamish said it was "vital" the bill was amended, saying the change would "maintain the Forestry Commission but within a devolved settlement and adds a vital layer of parliamentary scrutiny".
She said: "The Forestry Commission has been a successful brand and that would have been lost under the SNP's centralisation agenda."
Scottish Tory MSP Peter Chapman said he was pleased that forestry agencies would not be part of the government, and also welcomed the removal of compulsory purchase powers for sustainable development cases.
Green member Andy Wightman said the bill as originally written would devolve forestry but then allow it to "fall back into the hands of Scottish ministers", saying that parliament, not government, should determine the governance of land management.
And Lib Dem Mike Rumbles said the change was "parliament working at its best", saying: "I couldn't understand why the Scottish government wants to centralise control over this and make them civil servants."