The health of paddlers, swimmers and surfers at 14 beaches across Scotland has been put at risk by pollution from overflowing sewers and farms, official figures reveal.

The annual survey of Scotland's bathing waters, due to be unveiled by the Scottish Environment Protection Agency (Sepa) this week, will show that contamination from human and animal faeces this summer has been worse than last year.

The two dirtiest beaches were at Heads of Ayr in South Ayrshire and Lunan Bay in Angus, which suffered so much pollution that they failed to meet basic sewage safety limits introduced 38 years ago. Last year, no beaches in Scotland breached these limits.

But this year three samples of water at Heads of Ayr in May and August contained levels of toxic E-coli bacteria in breach of the legal limits. According to Sepa, this was because heavy rain caused "sewer overflows" and washed animal waste from farmland and urban areas.

Another two beaches - Irvine in North Ayrshire and Eyemouth in the Borders - also recorded five sample failures between them. But four of these are liable to be discounted because they were correctly predicted by electronic warning signs at the beaches.

Ten other beaches - in Ayrshire, Argyll, Edinburgh, East Lothian, Angus, Moray and Highland - had single water samples that failed the safety limits this summer (see table below). The contamination from bacteria and viruses can cause ear and stomach infections and, in extreme cases, be fatal.

Next year, much tougher new standards will come into force, meaning that many more bathing waters will be classified as badly polluted. In June, Sepa estimated that as many as 20 could be officially rated as "poor" under the new system.

The pollution has come under fierce fire from environmental groups worried about the health implications. "It's very disappointing that Scotland's beautiful beaches continue to fail the most basic water quality standards," said Andy Cummins, campaigns director of Surfers Against Sewage.

"We are concerned that a wetter bathing season, combined with new, tougher water quality standards will result in a dramatic number of Scottish beaches failing water quality standards in the coming years."

Repeated discharges from sewers should be controlled and pollution from farmland should be reduced by better management, Cummins argued.

"Surfers Against Sewage are calling on the Scottish Government to require Scottish Water to warn water-users when untreated sewage is discharged into the sea, as water companies do in England and Wales."

Calum Duncan, from the Marine Conservation Society in Scotland, agreed that more beaches would fail to meet the new standards. "These results once again highlight the impact of heavy rainfall on water quality, washing sewage bacteria off fields and through overflows into some bathing waters," he said.

"Substantial continued investment is needed to identify and fix problem sewer overflows and to keep working with the farming community to manage rainwater and limit livestock access to water courses. Only then can we be confident of good water quality in all weather conditions."

Scottish Water, however, pointed out that last year it had achieved its best-ever environmental performance. "In the 2014 bathing season, we have not identified any circumstances where issues with assets led to a confirmed bathing water sample failure," said a company spokesman.

But he accepted that some sewers did make discharges after heavy rain. "Combined sewer overflows function as they are designed - to operate like safety valves to prevent flooding following storm conditions," he said.

According to the National Farmers' Union in Scotland, preventing pollution from leaking into streams was good management practice for farmers, as well as a legal requirement. The union has been working with Sepa to ensure that farmers are aware of the rules.

"Our advice tells farmers to 'mind the gap', reminding them of the minimum legal working distances from watercourses if they are storing or spreading fertiliser," said a union spokesman.

The Scottish Government pointed out that "almost all" of the 84 designated bathing waters in Scotland were likely to meet the minimum standard this year. But some beaches were polluted because of bad weather in August in the aftermath of Hurricane Bertha, a spokeswoman accepted.

She added: "The Scottish Government and Sepa will continue to work closely with key partners on providing public information at our bathing waters, and to protect, manage, and improve areas where water quality is at risk."

Sepa confirmed that monitoring results available on its website showed that 14 bathing waters had recorded pollution incidents in 2014, with two breaching the basic sewage safety limits. It declined to comment further in advance of this week's expected announcement.