"We're now down to less than 2%, I think it's I% of our energy comes from coal," the prime minister added.
He was speaking on a visit to an offshore wind farm in the Moray Firth.
First Minister Nicola Sturgeon said the comments were "crass and deeply insensitive" to mining communities.
She tweeted: "Lives and communities in Scotland were utterly devastated by Thatcher's destruction of the coal industry (which had zero to do with any concern she had for the planet)."
Labour said he should apologise for the "shameful" comments.
Mr Johnson was being quizzed about preparations for the COP26 climate summit in Glasgow, in November, during a two-day visit to Scotland.
Pushed on whether he would set a deadline for ending the extraction of fossil fuels, he said the UK had already transitioned away from coal in his lifetime, and he suggested Mrs Thatcher had inadvertently got the ball rolling.
He said: "Thanks to Margaret Thatcher, who closed so many coal mines across the country, we had a big early start and we're now moving rapidly away from coal altogether."
He is reported to have laughed and told reporters: "I thought that would get you going."
He said there is a "massive opportunity" to increase the use of more environmentally-friendly technologies.
But he also stressed that there needs to be a "smooth and sensible" transition from oil and gas to greener forms of power.
In 1984, there were 170 working collieries in Britain, employing more than 190,000 people but by 2015, they had all closed.
Mrs Thatcher's announcement that she planned to close 20 of them, led to the year-long miners' dispute.
Millions of people protested against pit closures and throughout the summer of 1984 there were violent clashes between striking miners and police, whose numbers often ran into several hundred at each confrontation.
Violence led to widespread use of the breach of the peace charge.
In October, it was announced that miners convicted during the strike would be pardoned by the Scottish government following an independent review.
Responding to Mr Johnson's comments, SNP Westminster leader, Ian Blackford, tweeted that Mrs Thatcher had "devastated communities across Scotland".
He wrote: "Many still bear the scars of brutal Tory cuts."
BBC Political Correspondent, Nick Eardley has tweeted that "a few Scottish Tories have their head in their hands tonight after what they thought had been a decent first trip to Scotland since January".
He added they had described the comments as an "unforced error", "not helpful" and "crass".
Labour is opposed to the opening of new coal mines, saying they are not compatible with the UK wanting to be a world leader in reducing carbon emissions.
But Labour leader, Sir Keir Starmer, tweeted that Mr Johnson's comments are "shameful".
He wrote: "Brushing off the devastating impact on those communities with a laugh, shows just how out of touch he is with working people".
And in a statement, shadow foreign secretary, Lisa Nandy, said the prime minister should apologise.
She said the remarks "reveal the Conservative party's utter disregard for the communities still scarred by Thatcher's closure of the mines and failure to deliver good jobs in their place".
"It is vital that a green transition is a fair transition" she added.