MEGARA is the new generation IFU and MOS optical spectrograph built for the 10.4m Gran Telescopio CANARIAS (GTC). The project was developed by a consortium led by UCM (Spain) that also includes INAOE (Mexico), IAA-CSIC (Spain) and UPM (Spain). The instrument arrived to GTC on March 28 th 2017 and was successfully integrated and commissioned at the telescope from May to August 2017. During the on-sky commissioning we demonstrated that MEGARA is a powerful and robust instrument that provides on-sky intermediate-to-high spectral resolutions R FWHM ~ 6,000, 12,000 and 20,000 at an unprecedented efficiency for these resolving powers in both its IFU and MOS modes. The IFU covers 12.5 x 11.3 arcsec 2 while the MOS mode allows observing up to 92 objects in a region of 3.5 x 3.5 arcmin 2. In this paper we describe the instrument main subsystems, including the Folded-Cassegrain unit, the fiber link, the spectrograph, the cryostat, the detector and the control subsystems, and its performance numbers obtained during commissioning where the fulfillment of the instrument requirements is demonstrated.