The conceptional design of the proposed linear electron-positron collider TESLA is based on 9-cell 1.3 GHz superconducting niobium cavities with an accelerating gradient of Eacc >= 25 MV/m at a quality factor Q0 > 5E+9. The design goal for the cavities of the TESLA Test Facility (TTF) linac was set to the more moderate value of Eacc >= 15 MV/m. In a first series of 27 industrially produced TTF cavities the average gradient at Q0 = 5E+9 was measured to be 20.1 +- 6.2 MV/m, excluding a few cavities suffering from serious fabrication or material defects. In the second production of 24 TTF cavities additional quality control measures were introduced, in particular an eddy-current scan to eliminate niobium sheets with foreign material inclusions and stringent prescriptions for carrying out the electron-beam welds. The average gradient of these cavities at Q0 = 5E+9 amounts to 25.0 +- 3.2 MV/m with the exception of one cavity suffering from a weld defect. Hence only a moderate improvement in production and preparation techniques will be needed to meet the ambitious TESLA goal with an adequate safety margin. In this paper we present a detailed description of the design, fabrication and preparation of the TESLA Test Facility cavities and their associated components and report on cavity performance in test cryostats and with electron beam in the TTF linac. The ongoing R&D towards higher gradients is briefly addressed.