The last-minute announcement comes amid an ongoing emergency in Ottawa, where several shootings have occurred on or near Parliament Hill.
Harper was to moderate an afternoon question-and-answer session with Yousafzai at a Toronto high school.
He was then scheduled to head to a downtown hotel, where the 17-year-old from Pakistan was to receive honorary Canadian citizenship.
Harper's spokesman says both events have been cancelled.
Officials in prime minister's office say Harper was rushed away from the Parliament building and is safe in an undisclosed location.