Let G be a finitely generated group. We investigate the graph ΓM(G), whose vertices are the maximal subgroups of G and where two vertices M1 and M2 are joined by an edge whenever M1∩M2≠1. We show that if G is a finite simple group then the graph ΓM(G) is connected and its diameter is 62 at most. We also show that if G is a finite group, then ΓM(G) either is connected or has at least two vertices and no edges. Finite groups G with a nonconnected graph ΓM(G) are classified. They are all solvable groups, and if G is a finite solvable group with a connected graph ΓM(G), then the diameter of ΓM(G) is at most 2. In the infinite case, we determine the structure of finitely generated infinite nonsimple groups G with a nonconnected graph ΓM(G). In particular, we show that if G is a finitely generated locally graded group with a nonconnected graph ΓM(G), then G must be finite.