We compute the phase diagram of twisted bilayer graphene near the magic angle where the occurrence of flat bands enhances the effects of electron-electron interactions and thus unleashes strongly correlated phenomena. Most importantly, we find a crossover between d+id superconductivity and antiferromagnetic insulating behavior near half filling of the lowest electron band when the temperature is increased. This is consistent with recent experiments. Our results are obtained using unbiased many-body renormalization group techniques combined with a mean-field analysis of the effective couplings. We provide a qualitative understanding by considering the competition between Fermi-surface nesting and van Hove singularities.