The SNP and Scottish Greens have published details of their new power sharing arrangement.
The deal will take the Greens into government for the first time anywhere in the UK.
It includes a commitment to hold a referendum on Scottish independence within the next five years, and preferably by the end of 2023.
First Minister Nicola Sturgeon gave details at a briefing alongside the two Scottish Greens co-leaders.
Opposition parties have described the arrangement as a "nationalist coalition of chaos" that will be a "disaster" for Scotland.
The agreement will see two Green MSPs appointed as junior ministers in Ms Sturgeon's government.
These ministers could be invited to attend cabinet meetings when their portfolios are being discussed, with the Green co-leaders attending cabinet at least twice a year.
BBC Scotland's political editor, Glenn Campbell, said the arrangement will "look like a coalition but fall short of a coalition".
What is in the agreement?
The pro-independence Greens have signed up to the bulk of the government's policy - but there will also be areas where they are in disagreement with the SNP, and they will be able to criticise it on those points.
These excluded areas include aviation policy, international relations, policy on fee-paying schools, fox hunting and Nato membership if Scotland becomes independent.
The co-operation agreement says the two parties will work together to provide "effective and responsible leadership for Scotland for this session of the Scottish Parliament, in the interests of Scotland, of the people who live in Scotland, and of future generations".
It says they will secure a referendum on Scottish independence "within the current parliamentary session on a specific date to be determined by the Scottish Parliament".
If the Covid crisis has passed, their intention would be for the referendum to be within the first half of the five-year parliamentary session.
UK Prime Minister Boris Johnson is adamant that another referendum should not happen any time soon - with BBC political correspondent Nick Eardley saying that stance is unlikely to change.
The partnership agreement also includes commitments to:
- Increase investment in active travel and public transport, with the aim of providing a "realistic and affordable" alternative to car use
- More support for the marine renewables and offshore wind sectors
- A 10-year £500m Just Transition Fund for the north east and Moray
- Increasing the level of the Scottish Child Payment to the full £20 within this parliamentary term
- Investing at least £1.8bn over this parliamentary session in energy efficiency and renewable heating
- Enhancing tenants rights and delivering 110,000 affordable homes by 2032
It is a new form of government at Holyrood and a first in the UK, and is based on the arrangements the New Zealand Greens have with Jacinda Ardern's government.
The Greens are the fourth largest party in the Scottish Parliament after winning eight seats in the election in May, while the SNP won 64 seats - leaving them one short of an overall majority.
The SNP had formed a minority government for the previous five years, and had relied on the support of the Greens to pass its annual budget.
Ms Sturgeon said the agreement was about "doing politics and governance better to find the solutions needed to solve the problems confronting the world today".
She added: "The spirit of co-operation and consensus-building is very much in keeping with the founding principles of our Scottish Parliament.
"We do not agree on everything but we are coming out of our comfort zones to focus on what we do agree on."
Scottish Greens co-leader Patrick Harvie said the "historic" arrangement could not have come at a more important time.
He said: "We must build a fairer and compassionate country and we must do everything in our power to tackle the escalating climate and nature emergencies to deliver a just transition for all. That is what this deal will do".
The deal has been struck with less than three months to go until the COP26 climate conference in Glasgow.
The Greens have been pressing the Scottish government to go further in tackling global warming in exchange for their support, and wants it to oppose any new oil and gas exploration in the North Sea.
But the agreement does not do this, and instead offers support for a "pre-production oil and gas licence climate checkpoint review".
The UK government is expected to announce soon whether extraction of oil and gas at the Cambo site near Shetland will be given approval.
The GMB union said workers across the energy sector were "looking on with real concern" and would be seeking assurances that the SNP-Green deal will not be a "one-way ticket to the dole queue".
The Greens are also opposed to the government's road building programme, and some businesses including fish farming have warned that Green policies could damage the economy if they are adopted by the government.
This new power-sharing partnership will take Greens into government for the first time anywhere in the UK.
That may have particular resonance in the months before the UN climate summit - COP26 - is held in Glasgow.
For Greens, it is about maximising policy influence, especially when it comes to tackling global warming.
For the SNP, it is about creating a more stable administration, able to see off opposition ambush.
Whatever else is agreed, this tie-up will give the Scottish government a majority at Holyrood to pass budgets, win confidence votes and make legislation - including for another independence referendum.
It looks a lot like a coalition but crucially the Greens have opt-outs from policies they don't like - retaining the ability to criticise the government of which they would become part
The Scottish Conservatives described the tie up between the two parties as a "nationalist coalition of chaos focused on splitting up the country and dividing Scotland with another bitter referendum".
Leader Douglas Ross said the agreement was "anti-jobs and anti-business" and would punish hardworking families, motorists, and the oil and gas industry.
The Conservatives have formally requested that the Greens no longer receive an opposition leader's spot at First Minister's Questions, which the party says would be in line with the precedent set by the Labour-Liberal Democrat government at Holyrood between 1999 and 2007.
Scottish Labour leader Anas Sarwar challenged the Greens to show they are not simply the SNP's "lackeys", and said the party needed to "rediscover their principles and fight for a greener Scotland rather than roll over to the SNP every time the going gets tough."
He added: "Months have been wasted negotiating this rubber-stamp for SNP policy - meanwhile, A&E is in crisis, we are facing a growing cancer emergency, and we are still waiting for the NHS Recovery Plan.
"Scotland needs a real alternative, which puts recovery before the old constitutional arguments."
Meanwhile Alex Cole-Hamilton, the new leader of the Scottish Liberal Democrats, told BBC Radio's Good Morning Scotland: "I think it looks like pretty thin gruel for the Green party, they'll soon realise that they will have to carry the can for all of the SNP's inadequacies on public policy."
The deal was approved by the Scottish cabinet on Friday morning, but still requires the approval of the decision-making bodies of both parties before it can take effect.
The SNP's national executive committee is due to meet on Saturday and the Greens have scheduled a meeting of their membership for Saturday 28 August.
Both sides want the deal to take effect before Holyrood returns with a statement on the programme for government on Tuesday 31 August.
Their deal follows two months of negotiations led by the Deputy First Minister John Swinney for the government and MSPs Ross Greer and Maggie Chapman for the Greens.