Voixa Consultors · corporate services in Spain
Immigration Act · Detention and procedure

Immigration Act (Organic Law 4/2000), articles 58 to 66: return, detention and procedure

The Immigration Act (Organic Law 4/2000), articles 58 to 66: the effects of expulsion and return, exemption for foreign nationals who cooperate against organised networks, the recovery and reflection period for victims of trafficking in human beings, and the effects of refusal of entry. They also cover interim measures, admission to detention centres for foreign nationals and the rights, duties, complaints and security measures there, the priority and ordinary expulsion procedures, enforcement of expulsion, appeals against decisions on foreign nationals and the obligations of carriers.

Unofficial English translation from the Spanish by Voixa Consultors S.L. Alexander Baranov is responsible for the translation. Source: Organic Law 4/2000 of 11 January on the rights and freedoms of foreign nationals in Spain and their social integration, consolidated text published by the BOE, last amended 19 March 2025, BOE-A-2000-544 ↗. Check wording, figures, dates and legal effect against the Spanish original before relying on this reading. Source snapshot: 11 November 2026. This page: Title III (continued), articles 58 to 66. Title IV (articles 67 to 72, coordination of public authorities) and the additional, transitional and final provisions are not translated.

Title III. Infringements in immigration matters and their penalty regime (continued)

Article 58. Effects of expulsion and return

1. Expulsion shall entail an entry ban on Spanish territory. The duration of the ban shall be determined in the light of the circumstances of each case and shall not exceed five years.

2. Exceptionally, where the foreign national represents a serious threat to public order, public security, national security or public health, an entry ban of up to ten years may be imposed.

In the circumstances determined by regulation, the competent authority shall not impose the entry ban where the foreign national has left national territory while administrative sanctioning proceedings were pending on any of the grounds referred to in letters a) and b) of article 53.1 of this Organic Law, or shall revoke an entry ban imposed on those same grounds where the foreign national leaves national territory within the period for voluntary compliance set in the expulsion order.

3. No expulsion proceedings shall be required for the return of foreign nationals in the following cases:

a) Those who, having been expelled, breach the entry ban on Spain.

b) Those who attempt to enter the country illegally.

4. Where an application for international protection is lodged by persons in any of the cases referred to in the preceding paragraph, the return may not be carried out until a decision has been taken not to admit the application for processing, in accordance with the rules on international protection.

Nor may pregnant women be returned where the measure may entail a risk to the pregnancy or to the mother’s health.

5. Return shall be ordered by the government authority competent for expulsion.

6. Where the return cannot be carried out within 72 hours, the judicial authority shall be asked to order the detention measure provided for in expulsion proceedings.

7. A return ordered under letter a) of paragraph 3 of this article shall entail restarting the computation of the entry-ban period set by the expulsion decision that was breached. Likewise, every return ordered under letter b) of the same paragraph of this article shall entail an entry ban on Spanish territory for a maximum period of three years.

Note that the highlighted phrase of paragraph 7 (former paragraph 6 in the wording given by Organic Law 14/2003) is declared unconstitutional and void by Constitutional Court Judgment 17/2013 of 31 January. Ref. BOE-A-2013-2167.

[Translator’s note: the highlighted phrase is shown in bold.]

Article 59. Cooperation against organised networks

1. A foreign national who is irregularly in Spain and is a victim of, injured party in or witness to an act of unlawful trafficking in human beings, illegal immigration, labour exploitation or unlawful trafficking in labour, or of exploitation in prostitution by abuse of his or her situation of need, may be exempted from administrative liability and shall not be expelled if he or she reports the perpetrators of or accomplices in that trafficking, or cooperates and collaborates with the competent authorities by providing essential information or, where applicable, by testifying in the corresponding proceedings against those perpetrators.

2. The competent administrative bodies responsible for investigating the sanctioning proceedings shall inform the person concerned of the provisions of this article so that he or she may decide whether to take this route, and shall make the appropriate proposal to the authority that is to decide, which may grant the foreign national a provisional residence and work authorisation in accordance with the procedure laid down by regulation.

The officer investigating the sanctioning proceedings shall report the steps taken under this paragraph to the authority responsible for investigating the criminal proceedings.

3. Foreign nationals who have been exempted from administrative liability may be offered, at their choice, assisted return to their country of origin or a residence and work authorisation on exceptional grounds, together with facilities for their social integration, in accordance with this Law, ensuring, where appropriate, their safety and protection.

4. Where the Public Prosecutor becomes aware that a foreign national against whom an expulsion decision has been issued appears in criminal proceedings as a victim, injured party or witness, and considers his or her presence essential for the conduct of judicial steps, the Public Prosecutor shall bring this to the attention of the competent government authority so that it may assess whether the expulsion should not be enforced; and, if the expulsion has already been enforced, the same course shall be followed so that the authority may authorise his or her return to Spain for the time needed to carry out the necessary steps, without prejudice to the possibility of adopting any of the measures provided for in Organic Law 19/1994 of 23 December on the protection of witnesses and experts in criminal cases.

5. The provisions of this article shall apply equally to foreign nationals who are minors, and the procedure must take into account their age and maturity and, in all cases, the paramountcy of the principle of the best interests of the minor.

6. The conditions for cooperation by non-profit non-governmental organisations whose purpose is the reception and protection of victims of the offences referred to in paragraph one shall be laid down by regulation.

Article 59 bis. Victims of trafficking in human beings

1. The competent authorities shall adopt the measures necessary to identify victims of trafficking in persons in accordance with article 10 of the Council of Europe Convention on Action against Trafficking in Human Beings of 16 May 2005.

2. Where the competent administrative bodies consider that there are reasonable grounds for believing that a foreign person in an irregular situation has been a victim of trafficking in human beings, they shall inform the person concerned of the provisions of this article and shall submit to the authority competent to decide the appropriate proposal for the grant of a recovery and reflection period, in accordance with the procedure laid down by regulation.

That recovery and reflection period shall last at least ninety days and must be sufficient for the victim to be able to decide whether he or she wishes to cooperate with the authorities in the investigation of the offence and, where applicable, in the criminal proceedings. Both during the victim identification phase and during the recovery and reflection period, no sanctioning proceedings shall be opened for the infringement in article 53.1.a), and any administrative sanctioning proceedings already opened against the person or, where applicable, the enforcement of any expulsion or return that may have been ordered, shall be suspended. Likewise, during the recovery and reflection period, the person shall be authorised to stay temporarily, and the competent administrations shall ensure the subsistence and, if necessary, the safety and protection of the victim and of his or her children who are minors or have a disability and who are in Spain at the time of identification; the provisions of paragraph 4 of this article concerning assisted return or the residence authorisation, and where applicable work authorisation if they are over 16 years of age, on exceptional grounds shall be extended to those children. At the end of the reflection period, the competent public administrations shall assess the personal situation of the victim in order to determine whether that period may be extended.

On an extraordinary basis, the competent public administration shall ensure the safety and protection of other persons who are in Spain and with whom the victim has family or any other ties, where it is shown that the lack of protection in which they would be left in the face of the alleged traffickers constitutes an insurmountable obstacle to the victim agreeing to cooperate.

3. The recovery and reflection period may be refused or revoked on grounds of public order or where it becomes known that victim status has been invoked improperly. The refusal or revocation must state reasons and may be appealed as provided in Law 30/1992 of 26 November on the Legal Regime of Public Administrations and the Common Administrative Procedure.

4. The competent authority may declare the victim exempt from administrative liability and may offer him or her, at his or her choice, assisted return to the country of origin or a residence and work authorisation on exceptional grounds where it considers this necessary on account of his or her cooperation for the purposes of the investigation or of criminal proceedings, or in view of his or her personal situation, together with facilities for social integration, in accordance with this Law. Likewise, while the procedure for the residence and work authorisation on exceptional grounds is pending, he or she may be granted a provisional residence and work authorisation on the terms determined by regulation.

In processing the authorisations referred to in the preceding subparagraph, the victim may be exempted from submitting documents whose procurement would entail a risk to the victim.

5. The provisions of this article shall apply equally to foreign persons who are minors, taking into account their age and maturity and, in all cases, the paramountcy of the best interests of the minor.

6. The conditions for cooperation by non-profit non-governmental organisations whose purpose is the reception and protection of victims of trafficking in human beings shall be laid down by regulation.

Article 60. Effects of refusal of entry

1. Foreign nationals who are refused entry at the border under article 26.2 of this Law shall be obliged to return to their point of origin.

The decision refusing entry shall entail the immediate adoption of the measures necessary for the foreign national to return as quickly as possible. Where the return is going to be delayed by more than seventy-two hours, the authority that refused entry shall apply to the investigating judge to determine the place where they are to be detained until then.

2. Places of detention for foreign nationals shall not be of a penitentiary nature and shall be provided with social, legal, cultural and health services. Detained foreign nationals shall be deprived only of their freedom of movement.

3. During detention, the foreign national shall at all times be at the disposal of the judicial authority that authorised it, and the government authority must inform that judicial authority of any circumstance relating to the situation of the detained foreign nationals.

4. The arrest of a foreign national for the purpose of return following a refusal of entry shall be notified to the Ministry of Foreign Affairs and to the embassy or consulate of his or her country.

Article 61. Interim measures

1. From the moment sanctioning proceedings are opened in which expulsion may be proposed, the investigating officer may, in order to secure the final decision that may be issued, adopt any of the following interim measures:

a) Periodic reporting to the competent authorities.

b) Compulsory residence in a specified place.

c) Withdrawal of the passport or document proving nationality, after the person concerned has been given a receipt evidencing the measure.

d) Precautionary arrest by the government authority or its officers for a maximum period of 72 hours prior to the application for detention.

In any other case of arrest, the person shall be brought before the judicial authority within a period not exceeding 72 hours.

e) Preventive detention in detention centres, with prior judicial authorisation.

f) Any other interim measure that the judge considers appropriate and sufficient.

2. In sanctioning proceedings for infringements committed by carriers, if they breach the obligation to take charge of the illegally transported foreign national, the suspension of their activities, the provision of deposits or guarantees, or the immobilisation of the means of transport used may be ordered.

Article 62. Admission to detention centres

1. Once proceedings have been opened on any of the grounds referred to in letters a) and b) of article 54.1, in letters a), d) and f) of article 53.1 or in article 57.2 of this Organic Law, in which expulsion from Spanish territory may be proposed, the investigating officer may apply to the competent investigating judge for an order admitting the foreign national to a detention centre while the sanctioning proceedings are being processed.

The judge, after hearing the person concerned and the Public Prosecutor, shall decide by a reasoned order (auto) in which, in accordance with the principle of proportionality, he or she shall take into consideration the circumstances of the case and, in particular, the risk of non-appearance owing to a lack of domicile or identity documents, any actions by the foreign national intended to hinder or avoid expulsion, and the existence of any previous conviction or administrative penalties and of other pending criminal proceedings or administrative sanctioning proceedings. Likewise, in the event of serious illness of the foreign national, the judge shall assess the risk that detention poses to public health or to the health of the foreign national.

2. Detention shall be maintained for the time strictly necessary for the purposes of the proceedings, its maximum duration being 60 days, and no new detention may be ordered on any of the grounds provided for within the same proceedings.

3. Where the conditions described in paragraph 1 have ceased to be met, the foreign national shall be released immediately by the administrative authority in whose charge he or she is, which shall inform the judge who authorised the detention. In the same way and for the same reasons, the end of detention and the immediate release of the foreign national may be ordered by the judge, of the judge’s own motion or at the initiative of a party or of the Public Prosecutor.

4. Minors may not be admitted to detention centres, without prejudice to article 62 bis 1. i) of this Law. Unaccompanied foreign minors who are in Spain shall be placed at the disposal of the public child protection bodies as provided in the Organic Law on the Legal Protection of Minors and in accordance with the rules laid down in article 35 of this Law.

5. The opening of the proceedings, the interim measures of arrest and detention and the final decision in the expulsion proceedings against the foreign national shall be notified to the Ministry of Foreign Affairs and to the embassy or consulate of his or her country.

6. For the purposes of this article, the judge competent to authorise and, where applicable, to terminate detention shall be the investigating judge of the place where the arrest takes place. The judge competent to supervise the stay of foreign nationals in detention centres and in border non-admission rooms (Salas de Inadmisión) shall be the investigating judge of the place where they are located, and a specific court must be designated in those judicial districts where there are several. That judge shall hear, without further appeal, the requests and complaints made by detainees in so far as they affect their fundamental rights. That judge may likewise visit those centres when he or she learns of any serious failure to comply or when he or she considers it appropriate.

Article 62 bis. Rights of detained foreign nationals

1. Detention centres for foreign nationals are public establishments of a non-penitentiary nature; admission to and stay in them shall have a solely preventive and precautionary purpose, safeguarding the rights and freedoms recognised by the legal system, with no limitations other than those placed on freedom of movement, in accordance with the content and purpose of the judicial measure ordering admission. In particular, a foreign national subject to detention has the following rights:

a) To be informed of his or her situation.

b) To have respect for his or her life, physical integrity and health ensured, and in no case to be subjected to degrading treatment or to verbal or physical ill-treatment, and to have his or her dignity and privacy preserved.

c) To be assisted in exercising the rights recognised by the legal system, with no limitations other than those arising from his or her situation of detention.

d) To receive appropriate medical and health care and to be assisted by the social assistance services of the centre.

e) To have his or her admission to the centre notified immediately to the person he or she designates in Spain and to his or her lawyer, and to the consular office of the country of which he or she is a national.

f) To be assisted by a lawyer, who shall be appointed by the State (de oficio) where applicable, and to communicate with that lawyer in private, even outside the general hours of the centre, where the urgency of the case justifies it.

g) To communicate, during the hours set by the centre, with family members, consular officials of his or her country or other persons; these communications may be restricted only by judicial decision.

h) To be assisted by an interpreter if he or she does not understand or speak Castilian Spanish, free of charge if he or she lacks financial means.

i) To have his or her minor children with him or her, provided that the Public Prosecutor reports favourably on that measure and the centre has units that guarantee family unity and privacy.

Note that the phrase highlighted in bold in letter i) is declared inapplicable by Supreme Court Judgment of 10 February 2015. Ref. BOE-A-2015-5487.

[Translator’s note: the highlighted phrase is shown in bold.]

j) To contact non-governmental organisations and national, international and non-governmental bodies for the protection of immigrants.

2. The centres shall have adequately resourced social assistance and health care services. The conditions for providing these services shall be laid down by regulation.

3. Organisations lawfully constituted in Spain for the defence of immigrants and the relevant international bodies may visit detention centres; the conditions for such visits shall be laid down by regulation.

Article 62 ter. Duties of detained foreign nationals

A foreign national subject to detention shall be obliged:

a) To remain in the centre at the disposal of the investigating judge who authorised his or her admission.

b) To observe the rules governing the centre and to comply with the general instructions given by the management and the specific instructions received from officials in the lawful exercise of their duties, aimed at maintaining order and security within the centre, as well as those relating to his or her own personal hygiene and the cleanliness of the centre.

c) To maintain proper civil conduct and respect towards the officials and employees of the centre, visitors and other detained foreign nationals, refraining from insulting or threatening them, or from instigating or taking part in assaults, fights, disturbances and other individual or collective acts that disrupt coexistence.

d) To keep the physical facilities, furniture and other effects of the centre in good condition, avoiding the deliberate damage or rendering unusable of these and of the property or belongings of other detained foreign nationals or of officials.

e) To undergo a medical examination on entering and leaving the centre, and in those cases in which, for reasons of collective health assessed by the medical service and at its request, the director of the centre so orders.

Article 62 quater. Information and complaints

1. On admission to the centre, foreign nationals shall receive written information on their rights and obligations, matters of general organisation, the operating rules of the centre, the disciplinary rules and the means of making requests or complaints. The information shall be provided to them in a language they understand.

2. Detainees may make requests and complaints, orally or in writing, on matters relating to their situation of detention.

Such requests or complaints may also be submitted to the director of the centre, who shall deal with them if they fall within his or her competence or shall otherwise bring them to the attention of the competent authority.

Article 62 quinquies. Security measures

1. Internal surveillance and security operations in the centres may involve, in the manner and at the intervals laid down, inspections of the premises and rooms and, whenever necessary for security in the centres, searches of the persons, clothing and belongings of the detained foreign nationals.

2. Means of personal physical restraint or preventive separation of the aggressor in an individual room may be used to prevent acts of violence or injuries by foreign nationals, to prevent escapes or damage to the centre’s facilities, or in the face of resistance to the centre’s staff in the lawful exercise of their duties. The use of means of restraint shall be proportionate to the aim pursued, may not amount to a disguised penalty, and they shall be used only where there is no other, less onerous way of achieving the aim pursued and for the time strictly necessary.

3. The use of means of restraint shall be authorised in advance by the director of the centre, unless reasons of urgency do not allow this, in which case the director shall be informed immediately. The director must notify the judicial authority that authorised the detention, as soon as possible, of the adoption and cessation of the means of personal physical restraint, giving a detailed account of the facts that gave rise to their use and of the circumstances that might make it advisable to maintain them. The judge must, as quickly as possible and whenever the measure ordered was preventive separation of the aggressor, order that it be maintained or revoked, if it is still in force.

Article 62 sexies. Operation and internal regime of detention centres for foreign nationals

Each detention centre for foreign nationals shall have a director responsible for its operation, who for that purpose must adopt the necessary organisational guidelines, coordinating and supervising their implementation. The director shall also be responsible for adopting the measures necessary to ensure order and proper coexistence among the foreign nationals and to ensure respect for their rights, and for imposing measures on detainees who do not respect the rules of proper coexistence or the internal regime.

Article 63. Priority procedure

1. Once proceedings have been opened in which expulsion may be proposed because the case is one of those referred to in article 53.1.d), 53.1.f), 54.1.a), 54.1.b) and 57.2, they shall be processed as a priority.

The priority procedure shall likewise apply where, in the case of the infringements provided for in letter a) of paragraph 1 of article 53, any of the following circumstances exists:

a) a risk of non-appearance.

b) the foreign national avoids or hinders expulsion, without prejudice to actions taken in the exercise of his or her rights.

c) the foreign national represents a risk to public order, public security or national security.

In these cases, no period for voluntary departure may be granted.

2. While the priority procedure is being processed, and in the phase of enforcement of any expulsion ordered, the interim measures and detention provided for in articles 61 and 62 may be adopted.

3. The foreign national’s right to legal assistance, which shall be appointed by the State (de oficio) where applicable, and to be assisted by an interpreter if he or she does not understand or speak Castilian Spanish, free of charge if he or she lacks financial means, shall be guaranteed.

4. Once the proceedings have been initiated, the person concerned shall be given the decision to initiate them, duly reasoned and in writing, so that he or she may submit whatever arguments he or she considers appropriate within 48 hours, and shall be warned of the consequences of failing to do so.

5. If the person concerned or his or her representative does not submit arguments or propose evidence on the content of the initiating decision, or if the investigating officer, by reasoned decision, does not admit the evidence proposed as irrelevant or unnecessary, without changing the legal characterisation of the facts, the decision initiating the proceedings shall be treated as a proposed decision and shall be referred to the authority competent to decide.

If the proposal of evidence is accepted, the evidence shall be taken within a maximum period of three days.

6. In the case of letters a) and b) of paragraph 1 of article 53, where the foreign national proves that he or she previously applied for a temporary residence authorisation under article 31.3 of this Law, the body responsible for processing the expulsion shall suspend it until the application has been decided, and shall continue the proceedings if the application is refused.

7. The expulsion order in the cases provided for in this article shall be enforced immediately.

Article 63 bis. Ordinary procedure

1. Where expulsion is processed for cases other than those provided for in article 63, the procedure to be followed shall be the ordinary procedure.

2. The decision ordering expulsion processed under the ordinary procedure shall include a period for voluntary compliance within which the person concerned must leave national territory. That period shall be between seven and thirty days and shall run from the time the decision is notified.

The period for voluntary compliance with the expulsion order may be extended for a reasonable time in view of the circumstances of each particular case, such as the length of stay, having children in school in one’s care, or the existence of other family and social ties.

3. Both while the procedure is being processed and during the period for voluntary compliance, one or more of the interim measures provided for in article 61 may be adopted, except detention as provided for in letter e).

Article 64. Enforcement of expulsion

1. Once the period for voluntary compliance has expired without the foreign national having left national territory, he or she shall be arrested and escorted to the exit point through which the expulsion is to be carried out. If the expulsion cannot be enforced within seventy-two hours, the detention measure regulated in the preceding articles may be requested, which may not exceed the period laid down in article 62 of this Law.

2. In cases of extension of the period for voluntary compliance and in cases of postponement or suspension of enforcement of the expulsion, which shall be evidenced in a document duly notified to the person concerned, account shall be taken of the following guarantees for the foreign national affected:

a) Maintenance of family unity with the members who are in Spanish territory.

b) Provision of emergency health care and basic treatment of illness.

c) Access for minors, depending on the length of their stay, to the basic education system.

d) The special needs of vulnerable persons.

3. The expulsion decision shall be enforced, where applicable, at the expense of the employer penalised for the infringements provided for in article 53.2 a) or 54.1.d) of this Law or, in all other cases, at the expense of the foreign national if he or she has the financial means to pay for it. If neither of those conditions is met, the diplomatic or consular representative of his or her country shall be informed for the appropriate purposes.

4. Where a foreign national is arrested in Spanish territory and it is established that an expulsion decision has been issued against him or her by a Member State of the European Union, that decision shall be enforced immediately, without the need to open new expulsion proceedings. Authorisation from the investigating judge may be requested for his or her admission to a detention centre in order to secure enforcement of the expulsion penalty, in accordance with this Law.

5. Enforcement of the expulsion decision shall be suspended where an application for international protection is lodged, until that application has been declared inadmissible for processing or decided, in accordance with the rules on international protection.

6. It shall not be necessary to open expulsion proceedings:

a) to carry out the transfer, escorted by officials, of applicants for international protection whose application has been declared inadmissible for processing under Law 12/2009 of 30 October regulating the right of asylum and subsidiary protection because another State is responsible for examining the application under the international agreements to which Spain is a party, where that transfer takes place within the periods in which the responsible State is obliged to examine the application.

b) to carry out the transfer, escorted by officials, the maintenance, or the receipt, custody and transmission of travel documents, of foreign nationals in transit through Spanish territory, at the request of a Member State of the European Union, for the purposes of repatriation or removal by air.

Article 65. Appealability of decisions concerning foreign nationals

1. Administrative sanctioning decisions may be appealed as provided by law. Their enforceability shall be governed by the general rules.

2. In all cases, where the foreign national is not in Spain, he or she may lodge the appropriate appeals, both administrative and judicial, through the corresponding diplomatic or consular missions, which shall forward them to the competent body.

Article 66. Obligations of carriers

1. Where the Spanish authorities so determine in respect of routes originating outside the Schengen Area on which the intensity of migratory flows makes it necessary, for the purpose of combating illegal immigration and guaranteeing public security, every company, transport undertaking or carrier shall be obliged, when boarding has been completed and before the means of transport departs, to send to the Spanish authorities responsible for entry control the information on the passengers to be carried to Spanish territory, whether by air, sea or land, and irrespective of whether the carriage is in transit or to a final destination.

The information shall be transmitted electronically or, if that is not possible, by any other appropriate means, and shall include the first name and surnames of each passenger, his or her date of birth, nationality, the number of the passport or travel document proving his or her identity and its type, the border crossing point of entry, the transport code, the departure and arrival times of the transport, the total number of persons carried and the initial place of boarding. The authorities responsible for entry control shall keep the data in a temporary file, deleting them after entry and within twenty-four hours of their communication, except where needed in the exercise of their functions. Carriers must have informed passengers of this procedure and shall be obliged to delete the data within the same period of twenty-four hours.

2. Every company, transport undertaking or carrier shall be obliged to send to the Spanish authorities responsible for entry control the information on the number of return tickets not used by passengers whom they previously carried to Spain, whether by air, sea or land, and irrespective of whether the carriage was in transit or to a final destination, on routes originating outside the Schengen Area.

Where the Spanish authorities so determine, on the terms and for the purposes indicated in the preceding paragraph, the information shall also include, for passengers who are not nationals of the European Union, the European Economic Area or countries with which there is an international agreement extending the legal regime provided for citizens of those States, the first name and surnames of each passenger, his or her date of birth, nationality, and the number of the passport or travel document proving his or her identity.

The information referred to in this paragraph must be sent within a period not exceeding 48 hours from the expiry date of the ticket.

3. Likewise, every company, transport undertaking or carrier shall be obliged:

a) To duly check that the relevant passports, travel documents or identity documents and, where applicable, the corresponding visa that the foreign nationals must hold are valid and in force.

b) To take charge immediately of a foreign national whom it has carried to the relevant air, sea or land border of Spanish territory, if that foreign national has been refused entry because of deficiencies in the documentation required to cross borders.

c) To take charge of a foreign national who has been carried in transit to an air, sea or land border of Spanish territory, if the carrier that is to take him or her to the country of destination refuses to board him or her, or if the authorities of that country have refused him or her entry and returned him or her to the Spanish border through which he or she transited.

d) To carry the foreign nationals referred to in letters b) and c) of this paragraph either to the State from which it carried them, or to the State that issued the travel document on which they travelled, or to any other State that guarantees their admission and treatment compatible with human rights.

The company, transport undertaking or carrier that has a foreign national in its charge under any of the cases provided for in this paragraph must guarantee that person adequate living conditions while he or she remains in its charge.

4. The provisions of this article also apply where the air or sea transport is from Ceuta or Melilla to any other point in Spanish territory.

Where this sits

Previous: Penalties and expulsion (articles 50 to 57). All translated laws: Spanish laws in English.

Related on voixa.es: Spain residency for Moroccan nationals; The golden visa ended: the residency routes that remain.

Nothing here is advice on your own position, and this reading is not the official text. Spain publishes no official English version of this text; where the wording matters to a decision, read it against the Spanish original published in the BOE.