Under a weak assumption of the existence of a geodesic null congruence, we present the general solution of the Einstein field equations in three dimensions with any value of the cosmological constant, admitting an aligned null matter field, and also gyratons (a matter field in the form of a null dust with an additional internal spin). The general local solution consists of the expanding Robinson-Trautman class and the non-expanding Kundt class. The gyratonic solutions reduce to spacetimes with a pure radiation matter field when the spin is set to zero. Without matter fields, we obtain new forms of the maximally symmetric vacuum solutions. We discuss these complete classes of solutions and their various subclasses. In particular, we identify the gravitational field of an arbitrarily accelerating source (the Kinnersley photon rocket, which reduces to a Vaidya-type non-moving object) in the Robinson-Trautman class, and pp-waves, vanishing scalar invariants (VSI) spacetimes, and constant scalar invariants (CSI) spacetimes in the Kundt class.