British nationals stranded in Libya amid fierce fighting have been evacuated from Tripoli by a Royal Navy ship taking them to safety in Malta.

The Ministry of Defence said that HMS Enterprise, a survey ship on a routine deployment in the Mediterranean, was diverted to waters off the Libyan capital to collect an unspecified number of British nationals. The evacuees, believed to number around 100, were taken to HMS Enterprise in smaller boats.

The operation was launched after the Foreign Office announced it was temporarily closing its embassy and other consular operations in Libya following increasingly brutal battles between various militia groups fighting for control of Tripoli's airport, which saw 22 people killed on Saturday.

The MoD released a statement from HMS Enterprise's commanding officer, Cdr Mark Varta, saying: "This is a period of uncertainty for UK citizens based in Libya but we have been proud to play our part in enabling their move to safety. My ship's company have adapted to the challenge superbly, making as much space as possible and providing essential food, shelter and security for the journey."

The defence secretary, Michael Fallon, said: "I thank the crew of HMS Enterprise for their support and professionalism in carrying out this important task."

The 90-metre-long survey ship, normally based in Plymouth, is eight weeks into an 18-month mission carrying out surveys in the Bay of Biscay, Mediterranean, Red Sea and Gulf to update international navigation charts.

The Foreign Office had earlier warned Britons in Libya in its official travel advice for the country that they were "strongly urged to leave immediately by commercial means" because of the fighting around Tripoli and wider instability nationwide. The advice said some international flights were still leaving Misrata and Mitaga airports, to the west of Tripoli, but that those unable to leave independently could seek "assisted departure".

According to Libya's interim government, at least 22 people were killed on Saturday as militias fought for control of Tripoli's airport, taking the total death toll in fighting over recent weeks, which has also affected the city of Benghazi, to 236.

Libya is in the grip of its worst violence since the 2011 uprising that toppled Muammar Gaddafi. Islamist militias from the coastal city of Misrata led the assault on the airport, seeking to seize it from militias from the town of Zintan. The fighters are mainly former rebels who toppled Gaddafi with the aid of Nato air strikes.

As the fighting raged, many members of Libya's newly elected parliament met for the first time in Tobrouk, near the Egyptian border – a venue chosen by Abu Bakr Baiera, a prominent anti-Islamist politician. At the same time, Islamist militias overran several army bases and took control of the eastern city of Benghazi, the centre of the 2011 revolt.