Knowledge of the topology of the electronic ground state of materials has led to deep insights to novel phenomena such as the integer quantum Hall effect and fermion-number fractionalization, as well as other properties of matter. Joining two insulators of different topological classes produces fascinating boundary states in the band gap. Another exciting recent development is the bottom-up synthesis (from molecular precursors) of graphene nanoribbons (GNRs) with atomic precision control of their edge and width. Here we connect these two fields, and show for the first time that semiconducting GNRs of different width, edge, and end termination belong to different topological classes. The topology of GNRs is protected by spatial symmetries and dictated by the terminating unit cell. We have derived explicit formula for their topological invariants, and show that localized junction states developed between two GNRs of distinct topology may be tuned by lateral junction geometry. The topology of a GNR can be further modified by dopants, such as a periodic array of boron atoms. In a superlattice consisted of segments of doped and pristine GNRs, the junction states are stable spin centers, forming a Heisenberg antiferromagnetic spin 1/2 chain with tunable exchange interaction. The discoveries here are not only of scientific interest for studies of quasi one-dimensional systems, but also open a new path for design principles of future GNR-based devices through their topological characters.