The House of Commons voted narrowly on Wednesday night to extend Canada 's military deployment in Afghanistan by two years , giving Prime Minister Stephen Harper a foreign policy victory but only after an emotional and deeply partisan debate .