European Council President Donald Tusk has delivered a warning that "the problem of migration has not disappeared and will keep us busy in the years to come."
In a speech looking back at his five years in office, due to end on 1 December, Tusk said immigration was among the key challenges the bloc had faced - alongside Russia, Brexit and "protecting the unity of the eurozone."
Differences over asylum policy "triggered emotions and resentments on a great scale," he said, and his "number one priority" was to avoid it being a choice between "Open Europe and Fortress Europe - I felt it was essential to avoid painting black and white images."
One side was accused of xenophobia, while the other was accused of letting in terrorists, he said. There were differences between northern, southern and eastern members of the European Union as well, he added.
Special Report: Focus on the EU's migration crisis
"The way to ease the tension was, first and foremost, to make all the countries realise that there was no inherent contradiction between liberal democracy and effective control of our external borders," Tusk said.
"That we must help refugees, but not abandon our primary duty to protect our territory."
After saying that the problem had not disappeared, he said: "We have succeeded in persuading most actors to calm their emotions and focus on more pragmatic initiatives that protect our borders, on the fight with people smugglers, as well as cooperation with Libya and other African countries, and of course the deal with Turkey."
Tusk was following in the footsteps, 31 years on, of one of his early heroines, ex-UK Prime Minister Margaret Thatcher, in delivering the speech to mark the start of the academic year at the College of Europe in Bruges.
Other key quotes in his speech:
On Russia: "In this game, what is at stake is not only the future of independent Ukraine and the security of Central Europe, including that of my country (Poland) but the sovereignty of Europe as a political entity.... I had to publicly remind others, almost every week, that Russia is not our 'strategic partner', but our 'strategic problem.'"
On Brexit: "Only as part of a United Europe can the UK play a global role... after its departure the UK will become an outsider, a second-rate player, while the main battlefield will be occupied by China, the United States and the European Union."
On Brexit: "Can things still be turned around? Don't give up. We have had added time, we are already in extra time, perhaps it will even go to penalties."
On EU enlargement: "I share his (French president Macron's) dream of a truly sovereign Europe. I am convinced that we are capable of it, on condition that we will act as a sovereign and not the way it was recently in the case of EU enlargement. There will be no sovereign Europe without a stable Balkans integrated with the rest of the continent and you don't need to be a historian to understand this."
On President Macron: "And that is why when I hear Macron's words that 'we must reconsider our position with Russia, to rethink the strategic relation', I can only express hope that it will not happen at the cost of our common dreams about Europe's sovereignty."