The events leading to the formation of a pulsar begin when the core of a massive star is compressed during a supernova, which collapses into a neutron star. The neutron star retains most of its angular momentum, and since it has only a tiny fraction of its progenitor's radius (and therefore its moment of inertia is sharply reduced), it is formed with very high rotation speed. A beam of radiation is emitted along the magnetic axis of the pulsar, which spins along with the rotation of the neutron star. The magnetic axis of the pulsar determines the direction of the electromagnetic beam, with the magnetic axis not necessarily being the same as its rotational axis. This misalignment causes the beam to be seen once for every rotation of the neutron star, which leads to the "pulsed" nature of its appearance. The beam originates from the rotational energy of the neutron star, which generates an electrical field from the movement of the very strong magnetic field, resulting in the acceleration of protons and electrons on the star surface and the creation of an electromagnetic beam emanating from the poles of the magnetic field. This rotation slows down over time as electromagnetic power is emitted. When a pulsar's spin period slows down sufficiently, the radio pulsar mechanism is believed to turn off (the so-called "death line"). This turn-off seems to take place after about 10–100 million years, which means of all the neutron stars in the 13.6 billion year age of the universe, around 99% no longer pulsate. The longest known pulsar period is 8.51 seconds.
If you were wondering how the hell a pulsar could rotate 366 times in a second.