The Gaia spacecraft of the European Space Agency (ESA) has been securing observations of solar system objects (SSOs) since the beginning of its operations. Gaia Data Release 2 (DR2) contains the observations of a selected sample of 14,099 SSOs. These asteroids have been already identified and have been numbered by the Minor Planet Center. Positions are provided for each Gaia observation at CCD level. As additional information, the apparent brightness of SSOs in the unfiltered G band is also provided for selected observations. We explain the processing of SSO data, and describe the criteria we used to select the sample published in Gaia DR2. We then explore the data set to assess its quality. To exploit the epoch astrometry of asteroids in Gaia DR2 it is necessary to take into account the unusual properties of the uncertainty, as the position information is nearly one-dimensional. When this aspect is handled appropriately, an orbit fit can be obtained with post-fit residuals that are overall consistent with the a-priori error model that was used to define individual values of the astrometric uncertainty. The distribution of residuals allowed us to identify possible contaminants in the data set. Photometry in the G band was compared to computed values from reference asteroid shapes and to the flux registered at the corresponding epochs by the red and blue photometers (RP and BP). The overall astrometric performance is close to the expectations, with an optimal range of brightness G~12-17. In this range, the typical transit-level accuracy is well below 1 mas. For fainter asteroids, the growing photon noise deteriorates the performance. Asteroids brighter than G~12 are affected by a lower performance of the processing of their signals. The dramatic improvement brought by Gaia DR2 astrometry of SSOs is demonstrated by preliminary tests on the detection of subtle non-gravitational effects.