Midrapidity production of π±, K±, and (p¯)p measured by the ALICE experiment at the CERN Large Hadron Collider, in Pb-Pb and inelastic pp collisions at sNN=5.02 TeV, is presented. The invariant yields are measured over a wide transverse momentum (pT) range from hundreds of MeV/c up to 20 GeV/c. The results in Pb-Pb collisions are presented as a function of the collision centrality, in the range 0-90%. The comparison of the pT-integrated particle ratios, i.e., proton-to-pion (p/π) and kaon-to-pion (K/π) ratios, with similar measurements in Pb-Pb collisions at sNN=2.76 TeV show no significant energy dependence. Blast-wave fits of the pT spectra indicate that in the most central collisions radial flow is slightly larger at 5.02 TeV with respect to 2.76 TeV. Particle ratios (p/π, K/π) as a function of pT show pronounced maxima at pT≈3GeV/c in central Pb-Pb collisions. At high pT, particle ratios at 5.02 TeV are similar to those measured in pp collisions at the same energy and in Pb-Pb collisions at sNN=2.76 TeV. Using the pp reference spectra measured at the same collision energy of 5.02 TeV, the nuclear modification factors for the different particle species are derived. Within uncertainties, the nuclear modification factor is particle species independent for high pT and compatible with measurements at sNN=2.76 TeV. The results are compared to state-of-the-art model calculations, which are found to describe the observed trends satisfactorily. © 2020 American Physical Society. All rights reserved.