The porcine circovirus type 2 (PCV2) capsid protein (Cap) is an important antigen for the development of vaccines. To achieve high-level expression of recombinant PCV2 Cap in Pichia pastoris, the wild-type Cap (wt-Cap) and optimized Cap (opti-Cap) gene fragments encoding the same amino acid sequence of PCV2 were amplified by PCR using DNA from lymph nodes of postweaning multisystemic wasting syndrome-suffered pigs and synthesized based on the codon bias of the methylotrophic yeast P. pastoris, respectively. The wt-Cap and opti-Cap gene fragments were inserted into the site between EcoRI and NotI sites in pPIC9K, which was under the control of the alcohol oxidase 1 (AOX1) promoter and α-mating factor signal sequence from Saccharomyces cerevisiae. The recombinant plasmids, designated as pPIC9K-wt-Cap and pPIC9K-opti-Cap, were linearized using SacI and transformed into P. pastoris GS115 by electroporation. The expressed intracellular soluble opti-Cap reached 174 μg/mL without concentration in a shake flask and kept good reactivity to PCV2-specific positive sera, whereas the wt-Cap could not be detectable throughout three times electroporation. Strong specific PCV2-Cap antibodies were elicited from piglets immunized with vaccine based on opti-Cap. To the best of our knowledge, the achieved opti-Cap yield is the highest ever reported. Our results demonstrated that codon optimization play an important role on the high-level expression of a codon-optimized PCV2-Cap gene in P. pastoris, and the vaccine based on opti-Cap may be a potential subunit vaccine candidate.