1 This request for a preliminary ruling concerns the interpretation of Regulation (EC) No 883/2004 of the European Parliament and of the Council of 29 April 2004 on the coordination of social security systems (OJ 2004 L 166, p. 1, and corrigendum OJ 2004 L 200, p. 1), as amended by Regulation (EC) No 988/2009 of the European Parliament and of the Council of 16 September 2009 (OJ 2009 L 284, p. 423) (‘Regulation No 883/2004’).
2 The request has been made in proceedings between, on the one hand, the Instituto Nacional de la Seguridad Social (INSS) (National Institute for Social Security (INSS), Spain) and, on the other hand, the Tesorería General de la Seguridad Social (Social Security General Fund, Spain) and Mr Jesús Crespo Rey, concerning the calculation of the latter’s retirement pension.
3 The objective of the Agreement between the European Community and its Member States, of the one part, and the Swiss Confederation, of the other on the Free Movement of Persons, signed in Luxembourg on 21 June 1999 (OJ 2002 L 114, p. 6, ‘the Agreement on the free movement of persons’), in accordance with Article 1(a) and (d) thereof, is to accord to nationals of the Member States of the European Community and Switzerland a right of entry, residence, access to work as employed persons, establishment on a self-employed basis and the right to stay in the territory of the Contracting Parties and to accord the same living, employment and working conditions as those accorded to nationals.
4 Article 2 of that Agreement provides that nationals of one Contracting Party who are lawfully resident in the territory of another Contracting Party are not, in application of and in accordance with the provisions of Annexes I, II and III to that Agreement, to be the subject of any discrimination on grounds of nationality.
5 Article 8 of the Agreement provides as follows: ‘The Contracting Parties shall make provision, in accordance with Annex II, for the coordination of social security systems with the aim in particular of: (a) securing equality of treatment; (b) determining the legislation applicable; (c) aggregation, for the purpose of acquiring and retaining the right to benefits, and of calculating such benefits, all periods taken into consideration by the national legislation of the countries concerned; (d) paying benefits to persons residing in the territory of the Contracting Parties; (e) fostering mutual administrative assistance and cooperation between authorities and institutions.’
6 Article 9(1) and (2) of Annex I to the Agreement on the free movement of persons, entitled ‘Equal treatment’, provides: ‘1. An employed person who is a national of a Contracting Party may not, by reason of his nationality, be treated differently in the territory of the other Contracting Party from national employed persons as regards conditions of employment and working conditions, especially as regards pay, dismissal, or reinstatement or re-employment if he becomes unemployed. 2. An employed person and the members of his family referred to in Article 3 of this Annex shall enjoy the same tax concessions and welfare benefits as national employed persons and members of their family.’
7 Annex II to the Agreement on the free movement of persons, entitled ‘Coordination of social security schemes’, was amended by the Annex to Decision No 1/2012 of the Joint Committee established by the Agreement, of 31 March 2012 (OJ 2012 L 103, p. 51).
8 Under Article 1 of Annex II to the Agreement on the free movement of persons, as amended by the Annex to Decision No 1/2012: ‘1. The contracting parties agree, with regard to the coordination of social security schemes, to apply among themselves the legal acts of the European Union to which reference is made in, and as amended by, section A of this Annex, or rules equivalent to such acts. 2. The term “Member State(s)” contained in the legal acts referred to in section A of this Annex shall be understood to include Switzerland in addition to the States covered by the relevant legal acts of the European Union.’
9 Section A of Annex II to the Agreement on the free movement of persons, in its amended version, lists the ‘legal acts referred to’, which includes Regulation No 883/2004.
10 Article 52(1) of Regulation No 883/2004, entitled ‘Award of benefits’, which forms part of Title III of that regulation on special provisions concerning the various categories of benefits and, more specifically, of Chapter 5 on ‘Old-age and survivors’ pensions’, provides: ‘The competent institution shall calculate the amount of the benefit that would be due: (a) under the legislation it applies, only where the conditions for entitlement to benefits have been satisfied exclusively under national law (independent benefit); (b) by calculating a theoretical amount and subsequently an actual amount (pro rata benefit), as follows: (i) the theoretical amount of the benefit is equal to the benefit which the person concerned could claim if all the periods of insurance and/or of residence which have been completed under the legislation of the other Member States had been completed under the legislation it applies on the date of the award of the benefit. If, under this legislation, the amount does not depend on the duration of the periods completed, that amount shall be regarded as being the theoretical amount; (ii) the competent institution shall then establish the actual amount of the pro rata benefit by applying to the theoretical amount the ratio between the duration of the periods completed before materialisation of the risk under the legislation it applies and the total duration of the periods completed before materialisation of the risk under the legislations of all the Member States concerned.’
11 Article 56 of that regulation, also in Chapter 5, headed ‘Additional provisions for the calculation of benefits’, provides in paragraph 1: ‘For the calculation of the theoretical and pro rata amounts referred to in Article 52(1)(b), the following rules shall apply: … (c) if the legislation of a Member State provides that the benefits are to be calculated on the basis of incomes, contributions, bases of contributions, increases, earnings, other amounts or a combination of more than one of them (average, proportional, fixed or credited), the competent institution shall: (i) determine the basis for calculation of the benefits in accordance only with periods of insurance completed under the legislation it applies; (ii) use, in order to determine the amount to be calculated in accordance with the periods of insurance and/or residence completed under the legislation of the other Member States, the same elements determined or recorded for the periods of insurance completed under the legislation it applies; where necessary in accordance with the procedures laid down in Annex XI for the Member State concerned. …’
12 Annex XI to that regulation, entitled ‘Special provisions for the application of the legislation of the Member States’, is intended to take account of the particularities of the various social security systems of Member States in order to facilitate the application of the rules on coordination. It is apparent from recital 3 of Regulation No 988/2009 that a number of Member States have asked for entries concerning the application of their social security legislation to be included in this annex and have provided the European Commission with legal and practical explanations of their legislation and systems.
13 Paragraph 2 of the section ‘‘Spain’ in Annex XI to Regulation No 883/2004 provides: ‘(a) Under Article 56(1)(c) of this Regulation, the calculation of the theoretical Spanish benefit shall be carried out on the basis of the actual contributions of the person during the years immediately preceding payment of the last contribution to Spanish social security. Where, in the calculation of the basic amount for the pension, periods of insurance and/or residence under the legislation of other Member States have to be taken into account, the contribution basis in Spain which is closest in time to the reference periods shall be used for the aforementioned periods, taking into account the development of the retail price index. (b) The amount of the pension obtained shall be increased by the amount of the increases and revaluations calculated for each subsequent year for pensions of the same nature.’
14 Article 162 of the Ley General de la Seguridad Social (General Law on Social Security), in its consolidated version approved by Real Decreto Legislativo 1/1994 (Royal Legislative Decree 1/1994) of 20 June 1994 (BOE No 154 of 29 June 1994, p. 20568), applicable ratione temporis in the case in the main proceedings, provides the method for calculating the basic amount for the contributory retirement pension.
15 The Fifth Transitional Provision of the General Law on Social Security, entitled ‘Transitional provisions on the basic amount for the retirement pension’ states in the first sentence of the first paragraph that ‘from 1 January 2013, the basic amount for the retirement pension shall be the figure obtained by dividing by 224 the contribution bases for the 192 months immediately preceding the month before that of the operative event’.
16 The Orden TAS/2865/2003 (Order TAS/2865/2003) of 13 October 2003 (BOE No 250 of 18 October 2003, ‘the Order of 2003’), provides the conditions under which affiliation to the Spanish social security system may be obtained by means of a special agreement.
17 Article 2 of the Order of 2003 defines the persons who may normally conclude such an agreement. Essentially, these are workers not covered by social security.
18 Article 6 of that order sets the contribution basis applicable to those who have concluded such an agreement, who may choose, at the time they enter into the agreement, between the various monthly contribution bases as follows: - the maximum basis for ordinary risks of the contribution group corresponding to the person’s professional category, or in the scheme to which he belongs, under certain conditions; - the contribution basis resulting from the division by 12 of the sum of the bases for ordinary risks used for the payment of contributions during a determined period; - the minimum basis in force, on the date the special agreement takes effect, in the special social security scheme for self-employed persons; - a contribution basis between those determined in accordance with the three preceding possibilities.
19 Chapter II of the Order of 2003, entitled ‘Rules for special agreements’, includes a section 3 which brings together provisions on special agreements applicable to Spanish nationals and their children who work abroad and to beneficiaries of a foreign social security system resident in Spain.
20 Article 15 of the Order of 2003, which is in section 3, governs in that respect the ‘special agreement for Spanish emigrants and their children working abroad’ (‘the special agreement’). Article 15(1) provides that such an agreement may be concluded by ‘Spanish emigrants and their children who have Spanish nationality, independently of whether or not they have been affiliated to the Spanish social security system previously and regardless of the country they work in and whether or not that country has signed an agreement on social security affairs with the Kingdom of Spain’ and ‘Spanish emigrants and their children who have Spanish nationality, regardless of the country they worked in, upon their return to Spanish territory, as long as they have not been compulsorily included in any public social protection scheme in Spain’.
21 Furthermore, Article 15(4) provides: ‘The contribution basis in this special agreement shall in all cases be the minimum contribution basis that is at any time laid down in the General Social Security Scheme ...’
22 Mr Crespo Rey is a Spanish national. After paying social security contributions in Spain during several periods between August 1965 and June 1980 in accordance with contribution bases higher than the minimum set by the Spanish general social security scheme, he moved to Switzerland. The referring court states that during the period from 1 May 1984 to 30 November 2007 he paid contributions to the social security system of that State.
23 On 1 December 2007, Mr Crespo Rey signed a special agreement with the Spanish social security (‘the special agreement of 1 December 2007’) so that from that date until 1 January 2014 he paid contributions calculated on the minimum contribution basis set by the Spanish general social security scheme.
24 By decision of the INSS of 26 September 2014, Mr Crespo Rey was granted a retirement pension in Spain.
25 When calculating that pension, the INSS, in accordance with the Fifth Transitional Provision of the General Law on Social Security, took into account the amount of contributions paid by Mr Crespo Rey during the 192 months preceding his retirement, namely the period from 1 January 1998 to 31 December 2013.
26 The INSS treated the period from 1 December 2007 to 31 December 2013, during which the special agreement of 1 December 2007 applied, as a period completed in Spain. Accordingly, it applied the terms provided for in paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004 and took as the basis for the calculation for that period the contributions paid by Mr Crespo Rey under that agreement.
27 As for the period between 1 January 1998 and 30 November 2007, during which Mr Crespo Rey worked in Switzerland before concluding the special agreement, the INSS took into consideration, in accordance with paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, the contribution basis in Spain closest in time to the reference periods. The INSS considered that to be the contribution basis of December 2007, on the basis of which it calculated the first minimum contribution paid by Mr Crespo Rey under that agreement.
28 Mr Crespo Rey brought an action against that decision before the Juzgado de lo Social no 1 de La Coruňa (Social Court No 1, Corunna, Spain) challenging the calculation made by the INSS of his retirement pension.
29 After Mr Crespo Rey’s action was upheld by the Juzgado de lo Social no 1 de La Coruňa (Social Court No 1, Corunna) the INSS appealed that judgment before the referring court, the Tribunal Superior de Justicia de Galicia (High Court of Justice, Galicia, Spain).
30 The referring court is uncertain whether the national legislation at issue in the case before it is compatible with Article 45(1) TFEU in so far as, first, Article 15 of the Order of 2003 obligates the migrant worker to make contributions in accordance with the minimum contribution basis, with no possibility of choosing a different contribution basis and, second, the INSS treats the period during which that agreement applies as a period completed in Spain; as a result, when the theoretical amount of that worker’s retirement pension is calculated, only the minimum contributions paid under that agreement are taken into account, even though, before exercising his right to free movement, the worker concerned made contributions in accordance with contribution bases higher than the minimum.
31 In the event that the Court should hold that there is such incompatibility, the referring court questions whether it is necessary, in accordance with Article 45 TFEU and paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, to take into account, for the purposes of calculating the theoretical amount of a migrant worker’s retirement pension, the basis of the last actual contributions paid by the latter in Spain before he exercised his right to free movement, namely a higher contribution basis than the one under which the contributions paid by that worker under the special agreement of 1 December 2007 were calculated.
32 In those circumstances, the Tribunal Superior de Justicia de Galicia (High Court of Justice, Galicia) decided to stay the proceedings and to refer the following questions to the Court for a preliminary ruling: ‘(1) Must the expression “the contribution basis in Spain which is closest in time to the reference periods”, referred to in [paragraph 2 of the section ‘Spain’ in Annex XI] of Regulation No 883/2004, be interpreted as excluding those contribution bases arising from the application of Spanish domestic legislation under which a migrant worker who has returned to Spain and whose actual final Spanish contributions are higher than the minimum bases may conclude an agreement maintaining the contributions in accordance only with the minimum bases, whereas, if he were a non-migrant worker, he could have concluded such an agreement on higher bases? (2) In the event of an affirmative answer to the [previous question], and in accordance with [paragraph 2 of the section ‘Spain’ in Annex XI] of Regulation No 883/2004, do taking into account the last actual contributions made in Spain, duly updated, and considering the contribution period under the agreement maintaining contributions as a neutral period or interval constitute remedies appropriate for indemnifying the damage done to that worker?’
33 The Spanish Government contends that the request for a preliminary ruling is inadmissible on the ground that the referring court made an error in its assessment of the facts, the examination of which was not addressed on appeal, which has resulted in an interpretation being sought that has no connection with the reality of the case in the main proceedings.
34 In that regard, it should be recalled that, in proceedings under Article 267 TFEU, which are based on a clear separation of functions between the national courts and tribunals and the Court of Justice, any assessment of the facts in the case is a matter for the national court or tribunal. Similarly it is solely for the national court before which the dispute has been brought and which must assume responsibility for the forthcoming judicial decision, to determine, in the light of the particular circumstances of the case, both the need for a preliminary ruling in order to enable it to deliver judgment and the relevance of the questions which it submits to the Court. Consequently, where the questions submitted concern the interpretation of EU law, the Court is, in principle, bound to give a ruling (see, inter alia, judgments of 10 February 2011, Haribo Lakritzen Hans Riegel and Österreichische Salinen, C‑436/08 and C‑437/08, EU:C:2011:61, paragraph 41, and of 22 October 2009, Zurita García and Choque Cabrera, C‑261/08 and C‑348/08, EU:C:2009:648, paragraph 34 and the case-law cited).
35 The Court may refuse to rule on a question referred by a national court only where it is quite obvious that the interpretation of EU law that is sought bears no relation to the actual facts of the main action or its purpose, where the problem is hypothetical, or where the Court does not have before it the factual or legal material necessary to give a useful answer to the questions submitted to it (judgments of 5 December 2006, Cipolla and Others, C‑94/04 and C‑202/04, EU:C:2006:758, paragraph 25, and of 22 September 2016, Breitsamer und Ulrich, C‑113/15, EU:C:2016:718, paragraph 33).
36 That presumption of relevance cannot be rebutted by the simple fact that one of the parties to the main proceedings contests certain facts, the accuracy of which is not a matter for the Court to determine and on which the delimitation of the subject matter of those proceedings depends (judgments of 5 December 2006, Cipolla and Others, C‑94/04 and C‑202/04, EU:C:2006:758, paragraph 26, and of 22 September 2016, Breitsamer und Ulrich, C‑113/15, EU:C:2016:718, paragraph 34).
37 In the present case, the Spanish Government and the INSS have submitted before the Court that, contrary to what the referring court states, during the period from 1 December 2007 (the date on which the special agreement of 1 December 2007 was signed) to 31 December 2013 (the date of Mr Crespo Rey’s retirement) Mr Crespo Rey continued to work and pay contributions in Switzerland.
38 However, the question whether, at the time of entering into the agreement, Mr Crespo Rey had returned to Spain or continued to work and make contributions in Switzerland is a matter that forms part of the factual background of the case in the main proceedings, which is not for the Court to ascertain.
39 In those circumstances, the plea of inadmissibility raised by the Spanish Government must be rejected.
40 It should be observed that, according to the Court’s settled case-law, in the procedure laid down by Article 267 TFEU providing for cooperation between national courts and the Court of Justice, it is for the latter to provide the national court with an answer which will be of use to it and enable it to determine the case before it. To that end, the Court may have to reformulate the questions referred to it. The Court has a duty to interpret all provisions of EU law which national courts need in order to decide the actions pending before them, even if those provisions are not expressly indicated in the questions referred to the Court by those courts (judgment of 19 October 2017, Otero Ramos, C‑531/15, EU:C:2017:789, paragraph 39 and the case-law cited).
41 Consequently, even if, formally, the referring court has limited its questions to the interpretation of paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, that does not prevent this Court from providing the referring court with all the elements of interpretation of EU law that may be of assistance in adjudicating in the case pending before it, whether or not the referring court has referred to them in the wording of its questions. It is, in this regard, for the Court to extract from all the information provided by the national court, in particular from the grounds of the decision to make the reference, the points of EU law which require interpretation in view of the subject matter of the dispute (see, by analogy, judgment of 19 October 2017, Otero Ramos, C‑531/15, EU:C:2017:789, paragraph 40 and the case-law cited).
42 In the present case it is clear from the order for reference that the referring court asks whether the national legislation at issue in the main proceedings is compatible with Article 45 TFEU, to the extent that it obligates a migrant worker who concludes a special agreement with the Spanish social security system to make contributions in accordance with the minimum contribution basis, with the result that, when the theoretical amount of that worker’s retirement pension is calculated, in accordance with paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, the competent body treats the period covered by that agreement as a period completed in Spain and will take into consideration only the contributions paid under that agreement by that worker, even if, before exercising his right to free movement, he made contributions to the social security system in Spain in accordance with contribution bases higher than the minimum.
43 In a situation such as that at issue in the main proceedings, which concerns a migrant worker who is a national of a Member State and who worked and made contributions in Switzerland during a certain period, the national legislation at issue in the main proceedings should be assessed with regard to the provisions of the Agreement on the free movement of persons.
44 In the light of those considerations, it must be understood that, by its questions, which it is appropriate to consider together, the referring court is asking, is essence, whether the Agreement on the free movement of persons must be interpreted as precluding legislation of a Member State, such as that at issue in the main proceedings, which obligates a migrant worker who concludes a special agreement with the social security system of that Member State to make contributions in accordance with the minimum contribution basis, with the result that, when the theoretical amount of that worker’s retirement pension is calculated, the competent body of that Member State treats the period covered by that agreement as a period completed in that Member State and will take into consideration, for the purposes of that calculation, only the contributions paid by the worker under that agreement, even though, before exercising his right to free movement, the latter made contributions in that Member State in accordance with contribution bases higher than the minimum, and a non-migrant worker who did not exercise his right to free movement and who concludes such an agreement has the possibility of making contributions in accordance with contribution bases higher than the minimum.
45 As a preliminary point, it should be noted that Regulation No 883/2004 does not set up a common scheme of social security, but allows different national schemes to exist and its sole objective is to ensure the coordination of those schemes. Thus, according to the Court’s settled case-law, Member States retain the power to organise their own social security schemes (see, inter alia, judgment of 21 February 2013, Salgado González, C‑282/11, EU:C:2013:86, paragraph 35 and the case-law cited, and of 7 December 2017, Zaniewicz-Dybeck, C‑189/16, EU:C:2017:946, paragraph 38).
46 Therefore, in the absence of harmonisation at EU level, it is for the legislation of each Member State to determine, in particular, the conditions for entitlement to benefits (judgments of 21 February 2013, Salgado González, C‑282/11, EU:C:2013:86, paragraph 36 and the case-law cited, and of 7 December 2017, Zaniewicz-Dybeck, C‑189/16, EU:C:2017:946, paragraph 39).
47 In exercising those powers, Member States must nonetheless comply with EU law and, in particular, with the provisions of the FEU Treaty giving every citizen of the Union the right to move and reside within the territory of the Member States (judgments of 21 February 2013, Salgado González, C‑282/11, EU:C:2013:86, paragraph 37 and the case-law cited, and of 7 December 2017, Zaniewicz-Dybeck, C‑189/16, EU:C:2017:946, paragraph 40).
48 As is apparent from the preamble to and Articles 1 and 16(2) of the Agreement on the free movement of persons, the objective of the Agreement is to bring about, for the benefit of nationals of the European Union and of the Swiss Confederation, the free movement of persons in the territory of the contracting parties to that agreement based on the rules applying in the European Union, the terms of which must be interpreted in accordance with the case-law of the Court of Justice (judgments of 19 November 2015, Bukovansky, C‑241/14, EU:C:2015:766, paragraph 40, and of 21 September 2016, Radgen, C‑478/15, EU:C:2016:705, paragraph 36).
49 In that context, it should be noted that that objective includes, pursuant to Article 1(a) and (d) of the Agreement, the objective of granting to those nationals, inter alia, a right of entry, residence, access to work as employed persons and the same living, employment and working conditions as those accorded to nationals of the individual States in question (judgment of 21 September 2016, Radgen, C‑478/15, EU:C:2016:705, paragraph 37).
50 Accordingly, Article 8(a) of the Agreement on the free movement of persons states that the contracting parties are to make provision, in accordance with Annex II to that Agreement, for the coordination of social security systems with the aim of ensuring equal treatment.
51 Article 9 of Annex I to the Agreement on the free movement of persons, entitled ‘Equal treatment’, ensures the application of the principle of non-discrimination laid down in Article 2 of the Agreement in connection with the free movement of workers (judgments of 19 November 2015, Bukovansky, C‑241/14, EU:C:2015:766, paragraph 36 and the case-law cited, and of 21 September 2016, Radgen, C‑478/15, EU:C:2016:705, paragraph 40).
52 With regard to the case in the main proceedings, it must be noted that it appears, subject to the verifications to be made by the referring court, that Mr Crespo Rey exercised his right to free movement by working as an employee in Switzerland. It follows that he falls within the scope of the Agreement on the free movement of workers and may, therefore, rely on that Agreement with regard to his State of origin.
53 In the present case, it must be noted that the reference period for the calculation of Mr Cespo Rey’s retirement pension is, in accordance with the Fifth Transitional Provision of the General Law on Social Security, the period between 1 January 1998 and 31 December 2013.
54 The facts, as noted in paragraph 23 of this judgment, show that Mr Crespo Rey entered into the special agreement of 1 December 2007 under which he made contributions in accordance with the minimum contribution basis until 31 December 2013.
55 In the case in the main proceedings, the conclusion, by Mr Crespo Rey, of the special agreement of 1 December 2007 meant that the INSS based its calculation of the theoretical amount of his retirement pension on the minimum contribution basis.
56 Accordingly, in order to establish the relevant contribution basis for that period, the INSS took into account, in accordance with paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, the actual contributions made by Mr Crespo Rey during the years immediately preceding the payment of his last contribution to social security, namely the minimum contributions paid by him in accordance with the special agreement of 1 December 2007.
57 As for the period from 1 January 1998 to 30 November 2007 during which Mr Crespo Rey worked in Switzerland, and at which time he had not yet concluded that special agreement, the INSS took into consideration, in accordance with paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004, the contribution basis in Spain closest in time to the reference periods. The INSS considered that to be the contribution basis of December 2007, namely, once again, the minimum contribution basis under which Mr Crespo Rey paid his contributions under that agreement.
58 It follows that, as a result of the INSS treating the period covered by the special agreement of 1 December 2007 as a period of work completed in Spain, when calculating the theoretical amount of Mr Crespo Rey’s retirement pension, only the minimum contribution basis under which he paid his contributions under that agreement was taken into account.
59 It must be noted, in that regard, that it is clear from the order for reference that, before exercising his right of free movement and concluding the special agreement of 1 December 2007, Mr Crespo Rey made contributions to the Spanish social security scheme in accordance with contribution bases higher than the minimum applied under that agreement.
60 In accordance with Article 15(4) of the Order of 2003, a migrant worker is not free to continue to make contributions in accordance with higher bases under the special agreement, the amount of those contributions being mandatorily established, under such an agreement, in accordance with the minimum contribution basis set by the Spanish general social security scheme.
61 As a consequence, when, as in the case in the main proceedings, a migrant worker, before exercising his right to free movement and concluding a special agreement, has made contributions to the social security scheme of the Member State in question in accordance with contribution bases higher than the minimum, the contributions paid by that worker under the agreement he concluded do not correspond to those that he would have paid if he had continued to work under the same conditions in that Member State.
62 Moreover, it must be noted that the INSS and the Spanish Government acknowledged, in their written observations and at the hearing before the Court, that the national legislation at issue in the main proceedings does not impose such an obligation on non-migrant workers who did not exercise their right to free movement and therefore spent their entire working lives in Spain. The latter have the right to make contributions in accordance with contribution bases higher than the minimum.
63 It follows that, by requiring migrant workers who conclude a special agreement to pay contributions calculated in accordance with the minimum contribution basis, the national legislation at issue in the main proceedings establishes a difference of treatment which places migrant workers at a disadvantage compared to non-migrant workers who spent their entire working life in the Member State in question.
64 The INSS and the Spanish Government submit, in that regard, that the purpose of concluding a special agreement is to prevent the migrant worker suffering a reduction in the amount of his retirement pension because he exercised his right to free movement.
65 It must be stated, however, that in a situation such as that at issue in the main proceedings, a migrant worker who concludes a special agreement is, in reality, likely to see a non-negligible decrease in the amount of his retirement pension, since, as has already been noted in paragraph 59 of this judgment, when the theoretical amount of that pension is calculated, only the contributions paid by the worker under that agreement, namely contributions calculated in accordance with the minimum contribution basis, are taken into account.
66 It must be added that that would not be the case if that worker had, after exercising his right to free movement, made contributions only in another Member State, without concluding a special agreement.
67 Indeed, paragraph 2 of the section ‘Spain’ in Annex XI to Regulation No 883/2004 provides that, when calculating the basic amount for the migrant worker’s pension, ‘the contribution basis in Spain which is closest in time to the reference periods’ must be taken into account for the periods completed by that worker in other Member States.
68 Accordingly, in a situation such as that in the main proceedings, where the worker concerned, before exercising his right to free movement, made contributions to the social security scheme of the Member State in question in accordance with contribution bases higher than the minimum, the relevant contribution basis for the purposes of the calculation of his retirement pension would be the last contribution paid by that worker in that Member State, namely a contribution basis that is higher than the minimum provided for by the special agreement.
69 It follows that national legislation, such as that at issue in the main proceedings, which obligates a migrant worker who concludes a special agreement with the social security scheme of the Member State in question to make contributions in accordance with the minimum contribution basis, even if that worker, before exercising his right to free movement, made contributions in that State in accordance with contribution bases higher than the minimum, with the result that, when the theoretical amount of that worker’s retirement pension is calculated, the competent body of the Member State in question treats the period covered by that agreement as a period completed on its territory and takes into account, for the purposes of that calculation, only the minimum contributions paid by that worker under that agreement, places such a worker at a disadvantage compared with those who completed their entire working life in the Member State concerned.
70 To the extent that the referring court is uncertain as to what consequences it must draw from a possible incompatibility of national legislation with EU law, it must be borne in mind that the principle that national law must be interpreted in conformity with EU law requires national courts to do whatever lies within their jurisdiction, taking the whole body of domestic law into consideration and applying the interpretative methods recognised by domestic law, with a view to ensuring that EU law is fully effective and to achieving an outcome consistent with the objective pursued by it (judgment of 13 July 2016, Pöpperl, C‑187/15, EU:C:2016:550, paragraph 43 and the case-law cited).
71 It is true that this principle of interpreting national law in conformity with EU law has certain limits. Thus, the obligation on a national court to refer to the content of EU law when interpreting and applying the relevant rules of domestic law is limited by general principles of law and cannot serve as the basis for an interpretation of national law contra legem (judgment of 13 July 2016, Pöpperl, C‑187/15, EU:C:2016:550, paragraph 44 and the case-law cited).
72 If an interpretation of national law in conformity with EU law is not possible, the national court must fully apply EU law and protect rights which the latter confers on individuals, disapplying, if necessary, any provision in so far as its application would, in the circumstances of the case, lead to a result contrary to EU law (judgment of 13 July 2016, Pöpperl, C‑187/15, EU:C:2016:550, paragraph 45 and the case-law cited).
73 Where national law, in breach of EU law, provides for different treatment between a number of groups of persons, the members of the group placed at a disadvantage must be treated in the same way and made subject to the same arrangements as the other persons concerned. The arrangements applicable to members of the group placed at an advantage remain, for want of the correct application of EU law, the only valid point of reference (judgment of 13 July 2016, Pöpperl, C‑187/15, EU:C:2016:550, paragraph 46 and the case-law cited).
74 As is clear from the order for reference and has already been noted in paragraph 63 of the present judgment, non-migrant workers who conclude a special agreement are entitled to make contributions in accordance with contribution bases higher than the minimum. It is therefore this legal framework which constitutes a valid point of reference of that kind.
75 It is true that it is for the court dealing with the dispute to establish what, in national law, are the most appropriate means for achieving equality of treatment between migrant workers and non-migrant workers. However, it must be noted, in that regard, that that aim should, in principle, be achieved by granting also to migrant workers who conclude a special agreement the option to make contributions retroactively in accordance with contribution bases higher than the minimum and, as a consequence, to claim their right to a retirement pension on those new bases.
76 Having regard to all the foregoing considerations, the answer to the questions asked is that the Agreement on the free movement of persons must be interpreted as precluding legislation of a Member State, such as that at issue in the main proceedings, which obligates a migrant worker who concludes a special agreement with the social security system of that Member State to make contributions in accordance with the minimum contribution basis, with the result that, when the theoretical amount of that worker’s retirement pension is calculated, the competent body of that Member State treats the period covered by that agreement as a period completed in that Member State and will take into consideration, for the purposes of that calculation, only the contributions paid under that agreement, even though, before exercising his right to free movement, that worker made contributions in the Member State in question in accordance with contribution bases higher than the minimum, and a non-migrant worker who did not exercise his right to free movement and who concludes such an agreement has the option of making contributions in accordance with contribution bases higher than the minimum.
77 Since these proceedings are, for the parties to the main proceedings, a step in the action pending before the national court, the decision on costs is a matter for that court. Costs incurred in submitting observations to the Court, other than the costs of those parties, are not recoverable.