In this paper, we investigate the coexistence of two technologies that have been put forward for the fifth generation (5G) of cellular networks, namely, network-assisted device-to-device (D2D) communications and massive MIMO (multiple-input multiple-output). Potential benefits of both technologies are known individually, but the tradeoffs resulting from their coexistence have not been adequately addressed. To this end, we assume that D2D users reuse the downlink resources of cellular networks in an underlay fashion. In addition, multiple antennas at the BS are used in order to obtain precoding gains and simultaneously support multiple cellular users using multiuser or massive MIMO technique. Two metrics are considered, namely the average sum rate (ASR) and energy efficiency (EE). We derive tractable and directly computable expressions and study the tradeoffs between the ASR and EE as functions of the number of BS antennas, the number of cellular users and the density of D2D users within a given coverage area. Our results show that both the ASR and EE behave differently in scenarios with low and high density of D2D users, and that coexistence of underlay D2D communications and massive MIMO is mainly beneficial in low densities of D2D users.