A record two-fifths of electricity used in Scotland last year came from renewables, official figures have revealed.

Statistics from the UK Government's Department of Energy and Climate Change (DECC) showed 40.3% of energy consumption in 2012 was met by the sector - up from 36.3% the previous year and 24.1% in 2010.

Energy Minister Fergus Ewing said the figures showed renewables were "going from strength to strength".

The Scottish Government believes it is on course for half of electricity use to come from renewable sources by 2015, an interim target ahead of the goal of having the sector generate the equivalent of 100% of the country's electricity needs by 2020.

Scotland continues to produce more energy than it uses, with more than 26% of electricity generated here last year being exported.

Nuclear power provided 34.4% of electricity generated in Scotland in 2012, while 29.8% came from renewables, 24.9% came from coal, 8% from gas and 2.8% from oil and other sources.

Scotland's proportion of power from renewable sources was much higher than the rest of the UK. While 29.8% of electricity generated north of the border was from renewables, in England the sector only produced 8.2% of electricity, while in Wales and Northern Ireland renewables accounted for 8.7% and 15.9% of electricity generated.

Mr Ewing said: "These figures show that renewable electricity in Scotland is going from strength to strength, confirming that 2012 was a record year for generation in Scotland and that 2013 looks set to be even better. We can already see from the first nine months of 2013 that generation is 4% higher compared to the same period in 2012.

"The Scottish Government's target is to generate the equivalent of 100% of Scotland's gross annual electricity consumption from renewable sources by 2020, as part of a wider, balanced, low-carbon energy mix. These figures show that renewable generation in Scotland was at a record high last year, meeting around 40% of our electricity demand, and helping keep the lights on across these islands at a time when Ofgem (the energy regulator) are warning of the ever tightening gap between peak electricity demand and electricity supply."

He added: "Our support for renewable generation, combined with energy efficiency measures, will help protect Scotland's consumers by keeping energy prices down in the long term."

Environmental campaigners at WWF Scotland welcomed the figures, but said to meet the Scottish targets "significant amounts" of offshore wind power would needed.

Director Lang Banks said: "It's great news that Scotland's renewable energy capacity and output both continue to grow, and this year looks like being another record breaker. Most importantly, Scotland is further along the track to meeting its 2020 target than we thought, which means ever greater amounts of climate change emissions are being avoided every day.

"However, in order to remain on target Scotland will need to deploy significant amounts of offshore wind in the near future. It's therefore vital that the UK Government gives a stronger signal of its ambition on the growth of offshore wind in Scotland's seas, as well as the necessary support needed to deliver that growth. We also need to see a quick resolution to outstanding issues over transmission charges and the harnessing of renewable energy from Scotland's islands."

He added: "While the rest of the UK has become distracted by gas fracking and new nuclear power, Scotland has quietly got on with the business of deploying renewables at scale. It's clear from these figures that renewables are already ensuring the lights stay on, creating jobs and cutting emissions.

"By combining Scotland's superb renewable energy resource with greater energy efficiency and investment in the grid, Scotland can continue to avoid the need for polluting forms of energy."