Alex Salmond and Angus Robertson were among the high-profile casualties as the SNP lost more than a third of its seats in the general election.
The party won 35 of the 59 Scottish constituencies - a fall of 21 seats from the 56 they won in 2015.
The Conservatives secured 13 seats in Scotland - the party's best performance in the country since 1983.
Labour won seven seats and the Lib Dems four. The three pro-UK parties had won just one seat each in 2015.
The Tories saw big increases in their vote across the country, with the SNP vote dropping sharply.
Deputy First Minister John Swinney admitted that the issue of a second referendum on Scottish independence had played a "significant" role in the result.
The SNP MSP told the BBC: "We will take time and care to reflect on the outcome of this result.
"But we have to acknowledge that the question of a second independence was a significant motivator of votes against the SNP in this election, and we have to be attentive to that point."
The SNP won 36.9% of the votes, a drop of 13.1 percentage points since 2015.
The Scottish Tories doubled their share of the vote to 28.6%, with Labour up by 2.8 points at 27.1% and the Lib Dems down slightly to 6.8%.
The SNP's former leader Alex Salmond saw his majority crumble in Gordon, where Tory Colin Clark took the seat with 21,861 votes.
Despite his defeat, Mr Salmond insisted that people have "not seen the last of my bonnets and me".
He added: "The SNP have lost many fine parliamentarians this evening and that's a grievous blow to the SNP.
"But overall the result in Scotland shows the SNP will have won a majority of the seats in this country and the majority of the vote, something which I suspect the prime minister would like to be able to claim in the early hours of this morning but is not able to do so."
Douglas Ross of the Tories overturned a majority of 9,065 to defeat the SNP's leader at Westminster Angus Robertson by 4,200 votes in Moray.
The SNP's Tasmina Ahmed-Sheikh also lost Ochil and South Perthshire to the Tories, who were a distant third in 2015.
John Nicolson of the SNP lost Dunbartonshire East to Jo Swinson of the Liberal Democrats, who also saw Alistair Carmichael hold his Orkney and Shetland seat.
The final Scottish seat to declare was Fife North East, where there were three recounts before Stephen Gethins of the SNP was declared the winner after finishing just two votes ahead of the Lib Dem candidate.
The results mean that the SNP has lost its Westminster leader, chief whip, foreign affairs spokesman and international trade spokeswoman.
But the picture is less positive for the Conservatives across the UK, with the party losing its majority at Westminster and the prime minister facing calls for her resignation.
Speaking as she arrived at the Glasgow count, First Minister Nicola Sturgeon said that the SNP had won the election in Scotland, with the party achieving its second best performance ever in a Westminster election.
'Reflect on the result'
Asked about the impact of the lost SNP seats on her desire to hold a second independence referendum, Ms Sturgeon said: "Like most politicians I have not had any sleep and I am not going to take any rash decisions.
"Clearly I have to reflect on the result of the election and I will take time to do that. But it would be the wrong thing for me to do at this hour to take decisions before having had the opportunity to properly think about it.
"But properly think about it I will certainly do".
Scottish Conservative leader Ruth Davidson hailed a "historic" night for her party, which she said was largely due to Ms Sturgeon's attempts to "ram-raid through" a second independence referendum.
She added: "I think we have seen the country's reaction in the number of SNP seat's falling. Indyref2 is dead."
"Now it's time to get back to what matters to the people of Scotland - that's sorting out our schools, growing our economy and looking at our public services."
And Labour's Ian Murray, who increased his majority in Edinburgh to more than 15,000, said voters had "hammered the final nail into the independence coffin".
There was better news for the SNP in Paisley and Renfrewshire South, where Mhairi Black kept her seat despite a big drop in her share of the vote.
Ms Black, the youngest MP at Westminster in the last parliament, had her majority over Labour cut from about 6,000 to about 2,500.
Elsewhere, Stewart Hosie held Dundee East - which had been the safest seat in Scotland - for the SNP, while Angus MacNeil held on in the Western Isles, despite his share of the vote falling by nearly 14%.
Pete Wishart also held on for the SNP in Perth and Perthshire North after finishing just 21 votes ahead of the Tory candidate, while Tommy Sheppard held Edinburgh East.
An exit poll had predicted that the SNP would lose 22 of the 56 seats it won in the last election in 2015.
The poll, which was taken at polling stations across the UK, also suggested the Conservatives would fall short of an overall majority at Westminster.
SNP politicians had cast doubt on the exit poll result when it was first published - with many insisting the party would not lose as many as 22 seats.
Sorry, your browser cannot display this content.
Find your constituency
Enter a postcode or seat name