Answer
The compass needle is a small magnet. When the compass needle is brought close to a bar magnet, the magnetic field lines of the compass needle interact with the magnetic field lines of the bar magnet, which causes the compass needle to deflect.