Measurements of two-particle correlation functions and the first five azimuthal harmonics, v1 to v5, are presented, using 28 nb-1 of p+Pb collisions at a nucleon-nucleon center-of-mass energy of √sNN=5.02 TeV measured with the ATLAS detector at the LHC. Significant long-range "ridgelike" correlations are observed for pairs with small (|Δϕ|<π/3) and back-to-back pairs (|Δφ|>2π/3) over the transverse momentum range 0.4<pT<12 GeV and in different intervals of event activity. The event activity is defined by either the number of reconstructed tracks or the total transverse energy on the Pb-fragmentation side. The azimuthal structure of such long-range correlations is Fourier decomposed to obtain the harmonics νn as a function of pT and event activity. The extracted νn values for n=2 to 5 decrease with n. The ν2 and ν3 values are found to be positive in the measured pT range. The ν1 is also measured as a function of pT and is observed to change sign around pT≈1.5-2.0 GeV and then increase to about 0.1 for pT>4 GeV. The ν2 (pT), ν3 (pT), and ν4 (pT) are compared to the νn coefficients in Pb+Pb collisions at √sNN=2.76 TeV with similar event multiplicities. Reasonable agreement is observed after accounting for the difference in the average pT of particles produced in the two collision systems.