This article examines the case-law of the Court of Justice concerning security of residence for EU citizens and family members under Directive 2004/38. The relevant provisions of the Directive confer a right of permanent residence, and enhanced protection against expulsion, upon longer-term residents. It is argued that, in interpreting these provisions from 2006 onwards, the Court of Justice adopted a discourse which conceived of the rights as dependent on an individual’s social integration. The initial effect of the Court’s ‘turn’ to integration was benign, as it supported the retrospective extension of permanent residence, and ensured the efficacy of enhanced protection against expulsion. Later, however, the Court would treat integration as a precondition, in ways which would limit the rights of long-term residents who were not economically active or self-sufficient, or who had been sentenced to periods of imprisonment. That Court’s integration discourse was presumably influenced by developments in policy concerning third-country nationals at the state level which had linked immigration status to integration tests. The result was a selective approach to security of residence, which tended to deny protection to persons whose presence was unlikely to be favoured by Member States.