Narrowband power line communications (NB-PLC) is the central communications technology for the realization of smart power grids. For this reason, NB-PLC channels have been receiving substantial attention in recent years. These channels are characterized by periodic short-term variations of the channel transfer function (CTF) and strong noise with periodic statistics. In this work, we derive the capacity of discrete-time NB-PLC channels, accounting for the periodic properties of both the CTF and the noise. As part of the capacity derivation, we characterize the capacity achieving transmission scheme, which leads to guidelines for constructing a practical code that approaches the capacity as the blocklength increases. The capacity derived in this work is numerically evaluated and the results show that the optimal scheme achieves a substantial rate gain over previously proposed ad-hoc scheme. This gain is due to optimally accounting for the periodic properties of the channel and the noise.