McAvoy was born in Glasgow, Scotland, the son of Elizabeth (née Johnstone), a psychiatric nurse, and James McAvoy, a builder. McAvoy's parents divorced when he was seven, and he subsequently lived with his maternal grandparents, Mary and James Johnstone, in the Drumchapel area of Glasgow.
His mother lived with them intermittently but McAvoy has not been in contact with his father since childhood. McAvoy attended St. Thomas Aquinas Secondary in Jordanhill, Glasgow, a Catholic school, and briefly considered joining the priesthood. Graduated from the Royal Scottish Academy of Music and Drama in 2000. His sister, Joy McAvoy, is a singer.