Streptococcus pneumoniae is a piliated pathogen whose ability to circumvent vaccination and antibiotic treatment strategies is a cause of mortality worldwide. Pili play important roles in pneumococcal infection, but little is known about their biogenesis mechanism or the relationship between components of the pilus-forming machinery, which includes the fiber pilin (RrgB), two minor pilins (RrgA, RrgC), and three sortases (SrtC-1, SrtC-2, SrtC-3). Here we show that SrtC-1 is the main pilus-polymerizing transpeptidase, and electron microscopy analyses of RrgB fibers reconstituted in vitro reveal that they structurally mimic the pneumococcal pilus backbone. Crystal structures of both SrtC-1 and SrtC-3 reveal active sites whose access is controlled by flexible lids, unlike in non-pilus sortases, and suggest that substrate specificity is dictated by surface recognition coupled to lid opening. The distinct structural features of pilus-forming sortases suggest a common pilus biogenesis mechanism that could be exploited for the development of broad-spectrum antibacterials.