Measurements of the double-differential π± production cross section in the momentum range 100≤p≤800 MeV/c and angle range 0.35≤θ≤2.15 rad in proton-beryllium, proton-carbon, proton-aluminium, proton-copper, proton-tin, proton-tantalum, and proton-lead collisions are presented. The data were taken with the large-acceptance HARP detector in the T9 beam line of the CERN PS. The pions were produced by proton beams in a momentum range from 3 to 12.9 GeV/c hitting a target with a thickness of 5% of a nuclear interaction length. Tracking and identification of the produced particles was performed by using a small-radius cylindrical Time Projection Chamber (TPC) placed inside a solenoidal magnet. Incident particles were identified by an elaborate system of beam detectors. Results are obtained for the double-differential cross sections d2σ/(dpdθ) at six incident proton beam momenta [3, 5, 8, and 8.9 GeV/c (Be only) and 12 and 12.9 GeV/c (Al only)]. They are based on a complete correction of static and dynamic distortions of tracks in the HARP TPC, which allows the complete statistics of the collected data set to be used. The results include and supersede our previously published results and are compatible with these. Results are compared with the GEANT4 and MARS Monte Carlo simulation.