BUDAPEST, Oct 17 (Reuters) - Hungary's government has extended a freeze on retail mortgage interest rates until the end of June and widened the scope of the measure to mortgages with rates fixed for up to five years, Economic Development Minister Marton Nagy said in a statement.

Faced with his toughest test since taking power in 2010, nationalist Prime Minister Viktor Orban has capped mortgage rates and the prices of some basic foods and fuel to shield Hungarians from skyrocketing prices amid the war in Ukraine.

Despite the price caps, inflation has surged to two decade highs, while the forint has plumbed successive record lows versus the euro and the dollar this month, prompting the central bank to take emergency measures to shore up the currency.

On Friday, the bank hiked rates aggressively, taking short-term interbank rates to around 18% after the forint plunged, pressured by a widening trade gap and Hungary's lack of access to European Union funding due to the government's disputes with Brussels.

"We need to preserve the financial stability of families as well as the safety of accommodation," Nagy said in a statement.

He said the extended measure would apply to an additional 66,000 contracts to shield borrowers from a surge in borrowing costs.

In total, the freeze, in effect since the start of the year, will now apply to 350,000 contracts, curbing debt servicing costs by 140 billion forints ($326 million) in the 18 month period through to the end of June 2023.

At 0822 GMT, shares in Hungary's OTP Bank were 0.2% lower at 8,440 forints on the Budapest Stock Exchange, underperforming the wider market, which was up 0.5%.

($1 = 429.15 forints) (Reporting by Gergely Szakacs and Krisztina Than Editing by Mark Potter)