MADRID (Reuters) - Spain said on Friday it would allow its British residents to stay on if Britain leaves the European Union without a deal, giving them until the end of 2020 to apply for permanent residency and making it automatic for many.

A woman holds a banner after an informative Brexit talk by the "Brexpats in Spain" group for British retirees living in Spain, about how to access Spanish healthcare and other legal issues, at Calahonda Baptist Church in Calahonda, near Malaga, southern Spain, November 15, 2016. REUTERS/Jon Nazca

With less than a month until Britain is due to leave the EU on March 29, British Prime Minister Theresa May has yet to convince parliament to back the Brexit deal she negotiated. That leaves open the possibility of an abrupt exit with no agreement.

Spain has one of the largest British expatriate communities in the EU and has been at pains to reassure them that their rights will be protected after Brexit.

More than 300,000 British citizens are registered in Spain and an unknown number unregistered, the Spanish government said. The new residency process would apply to about 400,000 people, it estimated.

Continued residency rights are part of a series of measures announced on Friday to protect Britons’ rights in Spain in the event of a no-deal Brexit, including access to healthcare and social security.

These measures are conditional on the same terms applying to Spaniards living and working in Britain.

A measure calling on Britain to guarantee the rights of EU citizens in the event of a no-deal exit was approved by the Westminster parliament this week with government support.

“Our main objective is that no British or Spanish citizen is left unprotected, neither they nor their relatives,” Foreign Minister Josep Borrell told a news conference.

“There are a series of measures regarding professional access to public roles, social security, healthcare, which are extremely generous so that there is no break from the current situation, access to university and all kinds of economic activity,” Borrell said.

Spain plans at first to allow British nationals to stay if they hold a simple certificate of residency delivered to them, as to any other EU citizen, before Britain’s exit, Spain’s draft decree published on Friday showed.

If they do not hold such a document, they can still stay on until their situation is resolved.

British nationals and their families would then have to apply for a foreigner’s identity card by the end of 2020, to establish their permanent right to stay in the country.

If they already had permanent residency rights in Spain, the process will be “nearly automatic”, the draft decree said. In other cases, temporary residency will be granted.

The Brexit contingency legislation also applies to Gibraltar, Borrell said, while stressing that Madrid will insist on having a say on the application of any Brexit measure to the peninsula.

The bill will be sent immediately to parliament, before Prime Minister Pedro Sanchez’s government faces early elections.

The Spanish government approved a decree last month to hire 1,735 new public workers to deal with the consequences of Brexit, particularly in border and customs control.