A music publisher invests in songwriters and composers and controls musical compositions.
A record company invests in artists and controls master recordings.
Not all songwriters and composers are recording artists and many recording artists don’t write their own songs. Money is collected separately for songs and for master recordings.
For example, Bruno Mars co-writes his own songs, but has also written for other artists such as Natasha Beddingfield. Therefore, he has a music publishing agreement for the songs he doesn't record and a record deal for those he does.
Some of the writers that Bruno Mars co-writes with (such as Ari Levine) are not recording artists. Therefore, the only way they get paid is from music publishing royalties (unless they have a stake in the master recording).
You can learn more about the difference between compositions and master recordings here.