The biphasic assembly of Gram-positive pili begins with the covalent polymerization of distinct pilins catalyzed by a pilus-specific sortase, followed by the cell wall anchoring of the resulting polymers mediated by the housekeeping sortase. In Actinomyces oris, the pilus-specific sortase SrtC2 not only polymerizes FimA pilins to assemble type 2 fimbriae with CafA at the tip, but it can also act as the anchoring sortase, linking both FimA polymers and SrtC1-catalyzed FimP polymers (type 1 fimbriae) to peptidoglycan when the housekeeping sortase SrtA is inactive. To date, the structure-function determinants governing the unique substrate specificity and dual enzymatic activity of SrtC2 have not been illuminated. Here, we present the crystal structure of SrtC2 solved to 2.10-Å resolution. SrtC2 harbors a canonical sortase fold and a lid typical for class C sortases and additional features specific to SrtC2. Structural, biochemical, and mutational analyses of SrtC2 reveal that the extended lid of SrtC2 modulates its dual activity. Specifically, we demonstrate that the polymerizing activity of SrtC2 is still maintained by alanine-substitution, partial deletion, and replacement of the SrtC2 lid with the SrtC1 lid. Strikingly, pilus incorporation of CafA is significantly reduced by these mutations, leading to compromised polymicrobial interactions mediated by CafA. In a srtA mutant, the partial deletion of the SrtC2 lid reduces surface anchoring of FimP polymers, and the lid-swapping mutation enhances this process, while both mutations diminish surface anchoring of FimA pili. Evidently, the extended lid of SrtC2 enables the enzyme the cell wall-anchoring activity in a substrate-selective fashion.