This article addresses the data-based modeling and optimal control of district heating systems (DHSs). Physical models of such large-scale networked systems are governed by complex nonlinear equations that require a large amount of parameters, leading to potential computational issues in optimizing their operation. A novel methodology is hence proposed, exploiting operational data and available physical knowledge to attain accurate and computationally efficient DHSs dynamic models. The proposed idea consists in leveraging multiple recurrent neural networks (RNNs) and in embedding the physical topology of the DHS network in their interconnections. With respect to standard RNN approaches, the resulting modeling methodology, denoted as physics-informed RNN (PI-RNN), enables to achieve faster training procedures and higher modeling accuracy, even when reduced-dimension models are exploited. The developed PI-RNN modeling technique paves the way for the design of a nonlinear model predictive control (NMPC) regulation strategy, enabling, with limited computational time, to minimize production costs, to increase system efficiency and to respect operational constraints over the whole DHS network. The proposed methods are tested in simulation on a DHS benchmark referenced in the literature, showing promising results from the modeling and control perspective.