Migration helped to mitigate that. Regarding fertility rates so, the developed West is just ahead of the curve. With economic growth and stability, the rest of the world is following the same curve Europe and the US do for quite a while.
I think, that ultimately, global population will stabilize, including individual countries. There will be dips and spikes, as usual, overall so we should be fine as a species.
How to support the elderly in a world where the same GDP is produced by less and less working age people is a question so: using salaries as a basis for social securoty and public health care won't really work as well anymore. Taxing corporations and wealth (as in really wealthy, being a paper millionaire just because you happen to own a house does not qualify) is one option.