Purpose: Commercially available systems for ion beam reference dosimetry in water are mainly based on ionization chambers. In those systems, a large number of small detectors are typically arranged in a two-dimensional (2D) array or matrix to achieve high spatial resolution (order of several millimeters) and large field coverage at the same time. The goal of this work was to investigate the reliability of a detector of superior spatial resolution to perform three-dimensional (3D) ionization measurements in carbon ion pencil beams. Methods: The GEMPix is a small gaseous detector with a highly pixelated readout, consisting of a drift region (with 2.8 cm 3 9 2.8 cm 3 9 0.3 cm 3 volume), three gas electron multipliers (GEMs) for signal amplification and four Timepix ASICs with 55 µm pixel pitch and a total of 262,144 pixels. An integrated system was designed and built, which consists of a commercial water phantom with a three-axis motorized arm, a reference large-area ionization chamber for signal normalization to the beam output and the GEMPix itself. Measurements at different depths in water have been performed at the Italian National Centre for Oncological Hadrontherapy (CNAO) with three carbon ion beam energies. Lateral beam profiles measured with the GEMPix at the shallowest depth were compared to those measured with radiochromic EBT3 films in air in the position of the reference ionization chamber. The Timepix readout was calibrated in energy by using one independent depth scan with carbon ions of 150 mm range. Bragg peak curves were also simulated using the Monte Carlo FLUKA code as a reference. Results: Beam profiles measured with the GEMPix were smooth and showed similar shape and full width at half maximum when compared to those measured with radiochromic EBT3 films. Smooth, reproducible Bragg curves were obtained with statistical uncertainties of about 2%, matching FLUKA simulations of the Bragg curves within 15% for most data points. This difference is partially explained for the measurement with carbon ions of 150 mm range by a saturation effect in the GEMs. The high granularity of the readout allowed to produce 2D images of the deposited dose at different depths, as well as 3D data distributions. Conclusions: This paper demonstrates the capability of the GEMPix detector to measure the 3D dose distribution of carbon ions in water for a clinical pencil beam reliably. In the future, the detector area will be increased to cover fields of scanned beams. Measurements at higher beam intensities and with protons are planned.