Standard and Poor's has warned that Britain might lose its already precariously balanced AAA top credit rating if it votes to exit the EU in a referendum by the end of 2017.

Two other credit ratings agencies, Moody's and Fitch, have already taken away Britain's top rating and downgraded it to AA+.

In a "negative outlook" - a downgrade from "stable" - note released on 12 June, S&P wrote: "We see the government's target to reduce public-sector net borrowing from 4% of GDP during the fiscal year ending March 2016 to 2% of GDP by the fiscal year ending March 2017, as optimistic.

"We believe meeting this target will prove to be difficult given our understanding that most of the planned reduction is set to take place by reducing benefits and other current public expenditure, without touching health or pensions."

It added that "there is at least a one-in-three probability of a downgrade [from Triple-A] over the next two years".

Britain already has the highest debt-to-GDP ratio - 83% - of all the countries with a AAA rating.

S&P maintained that leaving the EU might mean that Britain could not finance its large deficit and high short-term debt. It also warned that even the uncertainty surrounding the result in the run-up to the referendum would harm the UK economy.

"In our opinion, the process of holding a referendum on the UK's membership of the EU is evidence of increasing risks to the effectiveness, stability and predictability of the UK's policy-making.

"This could negatively affect sustainable public finances, balanced economic growth and the response to economic or political shocks," the agency said.

The Treasury defended the decision to hold a referendum, saying that it needed to continue working through "the plan that is delivering economic security".

It added that it would resolve "the uncertainty around Britain's relationship with the EU".

"In doing this, we are seeking economic reforms that will deliver long term prosperity for the working people of Britain and the rest of Europe," it said.