Moody's has downgraded its outlook for the U.K. banking sector to negative from stable due to the expected impact of the U.K.'s decision to leave the European Union.

The credit agency also downgraded their outlook for 12 U.K. banks and building societies, including Lloyds (LYG) - Get Report , Barclays (BCS) - Get Report and HSBC (HSBC) - Get Report . It did not downgrade its outlook for the Royal Bank of Scotland.

Moody's expects the decision to leave the EU will reduce the profitability of the U.K. banks and building societies due to "lower economic growth and heightened uncertainty over the U.K.'s future trade relationship with the EU to lead to reduced demand for credit, higher credit losses and more volatile wholesale funding conditions for U.K. financial institutions," Moody's associate managing director Laurie Mayers said.

Barclays and HSBC were downgraded to negative from stable. Moody's said that the referendum uncertainty adds to "existing negative pressures on the bank's intrinsic creditworthiness, largely driven by the ... near-term profitability challenges" for Barclays.

Barclays shares were trading 3.8% up in morning trading in London, despite the outlook.

The credit agency said that it expects the U.K. will need to renegotiate "passporting" agreements with the EU. These allow companies to set up a base in the U.K. but carry out activities in other European Economic Area countries. That could lead to additional costs for banks if they cannot replicate current conditions, Moody's warned.

HSBC was downgraded to negative because these increased costs could "depress the bank's net interest margin and delay the group's planned issuance of loss-absorbing capital." HSBC shares were down 1.9% in early trading.

But the contingency planning done by the Bank of England and the banks should mean there is little short-term liquidity implications for U.K. banks, Moody's said. But with the debt market more volatile, the cost of issuing debt could be higher. "While this could make funding plans more challenging and further erode net interest margins, the overall impact should be limited," the credit agency said. 

Lloyds was downgraded to stable from positive and Royal Bank of Scotland (RBS) - Get Report was reaffirmed at positive.

Moody's said the positive outlook continues for the state-backed RBS reflected "the substantial progress the firm has made in its restructuring and ... [the] expectation that its credit fundamentals will continue to improve over the next 12-18 moths, which should not be materially affected by the economic and profitability pressures that are expected to arise following the outcome of the U.K. referendum."

Lloyds shares were up 2.2% in trading in London and RBS was up 2.9%.