What main mechanisms set the star formation rate (SFR) of galaxies? This PhD thesis is a quest into the influences of gas and active galactic nuclei (AGNs) on the SFR, with particular focus on massive galaxies at z~2. First, a new code if presented; SImulator of GAlaxy Millimeter/submillimeter Emission (SÍGAME) which can predict the atomic/molecular line emission in the far-infrared regime from galaxies. By post-processing the outputs of cosmological simulations of galaxy formation with sub-grid physics recipes, SÍGAME divides the interstellar medium (ISM) into different gas phases and derives density and temperature structure, employing locally resolved radiation and pressure fields. This method is used to predict the strengths of CO rotational transitions as well as the [CII] emission line in normal star-forming galaxies at z~2. A CO ladder close to that of our own Galaxy is found, but with CO-H2 conversion factors about 3 times smaller. For a set of 7 simulated galaxies at z~2, the relation between [CII] luminosity and SFR displays a slope significantly steeper than that found for observed galaxies at z<0.5. A corresponding relation on kpc-scales is established for the first time theoretically. Finally, a separate study uncovers the number fraction of AGNs among massive galaxies at z~2, by analyzing CHANDRA CDF-S X-ray data. It is found that about every fifth massive galaxy, quenched or not, contains an X-ray luminous AGN. Interestingly, an even higher fraction of low-luminosity AGNs emerges in the X-ray undetected galaxies when performing a stacking analysis, and preferentially in the quenched ones, lending support to the importance of AGNs in impeding star formation during galaxy evolution.