Central exclusive and semiexclusive production of pi(+)pi(-) pairs is measured with the CMS detector in proton-proton collisions at the LHC at center-of-mass energies of 5.02 and 13 TeV. The theoretical description of these non-perturbative processes, which have not yet been measured in detail at the LHC, poses a significant challenge to models. The two pions are measured and identified in the CMS silicon tracker based on specific energy loss, whereas the absence of other particles is ensured by calorimeter information. The total and differential cross sections of exclusive and semiexclusive central pi(+)pi(-) production are measured as functions of invariant mass, transverse momentum, and rapidity of the pi(+)pi(-) system in the fiducial region defined as transverse momentum p(T)(p) > 0.2GeV and pseudorapidity vertical bar eta(p)vertical bar < 2.4. The production cross sections for the four resonant channels f(0)(500), rho(0) (770), f(0)(980), and f(2)(1270) are extracted using a simple model. These results represent the first measurement of this process at the LHC collision energies of 5.02 and 13 TeV.