Real Madrid sealed their place in the Champions League last 16 with a narrow home victory over Paris St-Germain.