Transcranial magnetic stimulation (TMS) is a stimulation method in which a magnetic coil generates a magnetic field in an area of interest in the brain. This magnetic field induces an electric field that modulates neuronal activity. The spatial distribution of the induced electric field is determined by the geometry and location of the coil relative to the brain. Although TMS has been used for several decades, the biophysical basis underlying the stimulation of neurons in the central nervous system (CNS) is still unknown. To address this problem we developed a numerical scheme enabling us to combine realistic magnetic stimulation (MS) with compartmental modeling of neurons with arbitrary morphology. The induced electric field for each location in space was combined with standard compartmental modeling software to calculate the membrane current generated by the electromagnetic field for each segment of the neuron. In agreement with previous studies, the simulations suggested that peripheral axons were excited by the spatial gradients of the induced electric field. In both peripheral and central neurons, MS amplitude required for action potential generation was inversely proportional to the square of the diameter of the stimulated compartment. Due to the importance of the fiber's diameter, magnetic stimulation of CNS neurons depolarized the soma followed by initiation of an action potential in the initial segment of the axon. Passive dendrites affect this process primarily as current sinks, not sources. The simulations predict that neurons with low current threshold are more susceptible to magnetic stimulation. Moreover, they suggest that MS does not directly trigger dendritic regenerative mechanisms. These insights into the mechanism of MS may be relevant for the design of multi-intensity TMS protocols, may facilitate the construction of magnetic stimulators, and may aid the interpretation of results of TMS of the CNS.