Solubility is a requirement for many cellular processes. Loss of solubility and aggregation can lead to the partial or complete abrogation of protein function. Thus, understanding the relationship between protein evolution and aggregation is an important goal. Here, we analysed two deep mutational scanning experiments to investigate the role of protein aggregation in molecular evolution. In one data set, mutants of a protein involved in RNA biogenesis and processing, human TAR DNA binding protein 43 (TDP-43), were expressed in S. cerevisiae. In the other data set, mutants of a bacterial enzyme that controls resistance to penicillins and cephalosporins, TEM-1 beta-lactamase, were expressed in E. coli under the selective pressure of an antibiotic treatment. We found that aggregation differentiates the effects of mutations in the two different cellular contexts. Specifically, aggregation was found to be associated with increased cell fitness in the case of TDP-43 mutations, as it protects the host from aberrant interactions. By contrast, in the case of TEM-1 beta-lactamase mutations, aggregation is linked to a decreased cell fitness due to inactivation of protein function. Our study shows that aggregation is an important context-dependent constraint of molecular evolution and opens up new avenues to investigate the role of aggregation in the cell.