Directed and elliptic flow measurements for charged pions and protons are reported as a function of transverse momentum, rapidity, and centrality for 40A and 158A GeV Pb+Pb collisions, as recorded by the NA49 detector. Both the standard method of correlating particles with an event plane and the cumulant method of studying multiparticle correlations are used. In the standard method the directed flow is corrected for conservation of momentum. In the cumulant method elliptic flow is reconstructed from genuine four-, six-, and eight-particle correlations, showing the first unequivocal evidence for collective motion in A+A collisions at SPS energies.