Beam extraction from the K500 superconducting cyclotron is very challenging due to its long extraction path of about 330° with very high magnetic field gradient and low acceptance. The initial attempts of beam extraction showed that the pilot beams could successfully clear only a few magnetic channels. To investigate the causes of the beam loss, magnetic field measurements in different zones of the cyclotron were repeated. The total field has been generated by superposition of the measured field and the numerically computed field of the extraction elements. Based on these data, extensive beam dynamics simulation has been carried and beam distribution at the entry of the extraction path obtained by accelerated orbit calculations. The energy spread due to multi-turn deflector entry has been included in the simulation. The beam envelope along the extraction path as well as the beam transmission efficiency has been determined for different positions of the extraction elements. The radial positions of the extraction elements have been optimized parametrically to compute the maximum transmission efficiency. The present studies have enabled us to successfully extract the pilot beam (N4+) from the cyclotron with beam current of around 20 enA.