Yields of key crops have fallen significantly in this year’s harvest as a result of the hot summer and massive swings in weather, leaving farmers counting the cost and consumers facing higher prices for food.

After record heatwaves and drought, when rain finally arrived it caused problems in some areas, particularly the north and west, as farmers have struggled to bring in wet crops.

Early indications from the harvest are that yields of wheat are likely to be down by about a quarter, and those of staples such as potatoes, onions and carrots have plunged by as much as 20%. While the impact of lower yields will be cushioned by higher farmgate prices for produce, many farmers are turning to their banks for increased loans to tide them over as the costs of fuel, fertiliser and feed have all risen sharply.

Livestock farmers have been hit as feed prices have increased, while the long hot and dry spell forced many to dig into their feed reserves, and straw was in short supply in some areas. Milk yields were depressed by the hot weather, as was the fertility of pigs.

While food price rises have come as a shock to consumers – with prices to go up 5%, adding £7.15 to the monthly shopping bill, according to the Centre for Economics and Business Research – little of those increases will return to the farmer. Of the price of a loaf of bread, for instance, flour makes up only about a tenth.

“What farmers gain on the market swing, they lose on the yield roundabout,” explained Guy Smith, deputy president of the National Farmers’ Union. “Farmers are price takers, not price makers, and input prices have gone up under other pressures.”

Arla, the dairy co-operative behind brands such as Lurpak and Anchor, is taking the “extraordinary measure” of paying out all its £278m profit, instead of only part, to its 11,200 farmers, including about 2,500 in the UK, after their output suffered in the drought.

The NFU estimates that fertiliser prices have gone up by 23% this year, while motor fuel is up by about a fifth and other energy costs by 16%. Feed such as barley has risen 12% in price, while soybeans and similar feed are up 16%.

Wheat in particular has been “on a rollercoaster” in terms of price, according to Smith. Hikes of more than 30% over the summer, when milling wheat rose to £190 a tonne from about £140 a few months earlier, fell back on bullish news of US harvests. Prices are now uncertain following rumours that Russia may impose limits on its grain exports.

These swings have taken a toll on farmers. Borrowing was already up £300m on last year to nearly £19bn, according to the Bank of England, and expected to rise further.

“The financial impact of this year’s weather is now evident,” said Anand Dossa, economist at the NFU. “We are beginning to see farmers turn to their banks to get loans to tide them over.”

The international picture is also one of economic gloom for farmers. German harvests are forecast to be the lowest in 15 years, while Russia and Ukraine, the third and ninth biggest wheat producers globally, have suffered a combination of heavy rains and heatwaves which has lowered the quality. German farmers are likely to face economic losses of €2.5bn from this year’s weather, according to industry estimates, while the combined drought losses across Europe are estimated at $4bn.

Pig farmers were braced for the impact on feed prices later in the year, said Zoe Davies, chief executive of the National Pig Association. She said the impact of the summer’s heat on pig fertility would not be apparent for at least a month, though many farmers said their sows were well used to dealing with heat.

Phil Stocker, chief executive of the National Sheep Association, reported: “The biggest issue we are concerned about will be the potential feed shortages in the winter.” This is in part owing to sheep farmers having to put out feed saved for this winter much earlier than usual, but also the lack of grass growing over the dry summer and, according to Stocker, biomass burners competing with farmers.

The weather this autumn will be crucial for many vegetables, added Jack Ward, chief executive of the British Growers Association. Brassicas such as cabbage, broccoli and brussels sprouts need cool weather through the autumn to slow their growth and provide greens for Christmas dinner tables.

The Met Office is forecasting a 40% chance that temperatures will be above average from September to the end of November. This year’s swings, from the Beast from the East causing cold, wet weather in March, to the heatwave and drought of the summer, followed by a wet August in places, have emphasised how food production can vary on the conditions. “The weather always has the last laugh, for farmers,” said Smith.

But even these extremes have paled in comparison with the biggest uncertainty they face, over Brexit.

“We have a mountain to climb,” said Ward. “It is scary, really scary.” He said a no-deal Brexit next spring could wreak havoc on food imports, as Spain in particular is a key supplier of fresh vegetables to the UK in the early part of the year.

“Life was easy under the EU when things moved seamlessly [across borders],” he said. “If there is no deal, that comes to a shuddering halt.”

Dossa said long-term confidence among farmers was at an eight-year low, owing to uncertainties over Brexit, and at least a fifth of farmers are intending not to invest in their farms this year as a result. Food price rises driven by the drought may turn out to be much smaller than those resulting from Brexit, if some predictions come to pass.

Smith noted that UK food prices are still low in historic terms, as in the 1950s households spent about half their disposable income on food, but the variability should make the government take notice. “What this year shows is that you can’t take food production, and food supplies, for granted,” he said.