We model for the first time capillarity in fully compositional three-phase flow, with higher-order finite-element (FE) methods. Capillary pressure gradients may be an important driving force, particularly in layered or fractured porous media, which exhibit sharp discontinuities in permeability. We introduce a simple local computation of the capillary pressure gradients, propose a fractional-flow formulation in terms of the total flux, and resolve complications arising from gravity and capillarity in the upwinding of phase fluxes. Fractures are modeled with the crossflow equilibrium concept, which allows large timesteps and includes all physical interactions between fractures and matrix blocks. The pressure and flux fields are discretized by the mixed hybrid finite-element method, and mass transport is approximated by a higher-order local discontinuous Galerkin (DG) method. Numerical-dispersion and grid-orientation effects are significantly reduced, which allows computations on coarser grids and with larger timesteps. The main advantages in the context of this work are the accurate pressure gradients and fluxes at the interface between regions of different permeabilities. The phase compositions are computed with state-of-the-art phase-splitting algorithms and stability analyses to guarantee the global minimum of Gibbs free energy. Accurate compositional simulation motivates the use of an implicitpressure/explicit-composition (IMPEC) scheme, and we discuss the associated Courant-Friedrichs-Lewy (CFL) condition on the timesteps. We present various numerical examples on both core-and large-scale, illustrating the capillary end effect, capillary-driven crossflow in layered media, and the importance of capillarity in fractured media for three-phase flow.