Measurements of two-particle correlation functions and the first five azimuthal harmonics, ${v}_{1}$ to ${v}_{5}$, are presented, using 28 ${\mathrm{nb}}^{\ensuremath{-}1}$ of $p+\text{Pb}$ collisions at a nucleon-nucleon center-of-mass energy of $\sqrt{{s}_{NN}}=5.02$ TeV measured with the ATLAS detector at the LHC. Significant long-range ``ridgelike'' correlations are observed for pairs with small relative azimuthal angle ($|\ensuremath{\Delta}\ensuremath{\phi}|<\ensuremath{\pi}/3$) and back-to-back pairs ($|\ensuremath{\Delta}\ensuremath{\phi}|>2\ensuremath{\pi}/3$) over the transverse momentum range $0.4<{p}_{\mathrm{T}}<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 ${v}_{n}$ as a function of ${p}_{\mathrm{T}}$ and event activity. The extracted ${v}_{n}$ values for $n=2$ to 5 decrease with $n$. The ${v}_{2}$ and ${v}_{3}$ values are found to be positive in the measured ${p}_{\mathrm{T}}$ range. The ${v}_{1}$ is also measured as a function of ${p}_{\mathrm{T}}$ and is observed to change sign around ${p}_{\mathrm{T}}\ensuremath{\approx}1.5$--2.0 GeV and then increase to about 0.1 for ${p}_{\mathrm{T}}>4$ GeV. The ${v}_{2}({p}_{\mathrm{T}})$, ${v}_{3}({p}_{\mathrm{T}})$, and ${v}_{4}({p}_{\mathrm{T}})$ are compared to the ${v}_{n}$ coefficients in $\mathrm{Pb}+\mathrm{Pb}$ collisions at $\sqrt{{s}_{NN}}=2.76$ TeV with similar event multiplicities. Reasonable agreement is observed after accounting for the difference in the average ${p}_{\mathrm{T}}$ of particles produced in the two collision systems.