Just to add to this, the pacemaker itself is no where near your heart, there are wires that go from the pacemaker into the heart chambers.
The pacemaker is usually located in the upper chest (in babies they put them in the abdomen) think about where a chest pocket is on a jacket.
The incision is small, about 2-3cm. When the cardiologist implants it they make a pocket in the flesh so the pacemaker is very near the surface.
The electrodes are connected tot he pacemaker with tiny screws that can be undone with a special screwdriver.
@LoisPrice
Pacemakers don't pace all the time, they detect whether your heart is beating at an appropriate rate and if it is too slow it will, sort of, give an electrical signal to initiate a contraction.
An ICD, as @Greybeardy states is a different thing, it IS used to stop the heart fibrillating.
Now these can be programmed 'off'. Again with a programmer and a magnet.
If an ICD is not working correctly and giving shocks when it shouldn't you can temporarily turn it off with a 'blue doughnut' magnet until the person can get to a hospital.
https://mrp.io/magnet-pacemaker-metronic-blue-donut-4-package-for-use-with-difibrillator.html