The formation of two-dimensional (2D) polyaniline (PANI) has attracted considerable interest due to its expected electronic and optoelectronic properties. Although PANI has been discovered over 150 years ago, obtaining an atomically well-defined 2D PANI framework has been a longstanding challenge. Here, we describe the synthesis of 2D PANI via the ‘direct’ pyrolysis of hexaaminobenzene trihydrochloride single crystals in solid state. The 2D PANI consists of three phenyl rings sharing six nitrogen atoms, and its structural unit has the empirical formula of C3N. The topological and electronic structures of the 2D PANI were revealed by scanning tunnelling microscopy and scanning tunnelling spectroscopy combined with a first-principle density functional theory calculations. The electronic properties of pristine 2D PANI films (undoped) showed ambipolar behaviours with a Dirac point of –37 V and an average conductivity of 0.72 S/cm. After doping with hydrochloric acid, the conductivity jumped to 1.41 × 103 S/cm, which is the highest value for doped PANI reported to date. Although the structure of 2D PANI is analogous to graphene, it contains uniformly distributed nitrogen atoms for multifunctionality; hence, we anticipate that 2D PANI has strong potential from wet-chemistry to device applications beyond linear PANI and other 2D materials.