The compartmentalization of distinct templates in protocells and the exchange of templates between them (migration) are key elements of a modern scenario for prebiotic evolution. Here we use the diffusion approximation of population genetics to study analytically the steady-state properties of such prebiotic scenario. The coexistence of distinct template types inside a protocell is achieved by a selective pressure at the protocell level (group selection) favoring protocells with a mixed template composition. In the degenerate case, where the templates have the same replication rate, we find that a vanishingly small migration rate suffices to eliminate the segregation effect of random drift and so to promote coexistence. In the non-degenerate case, a small migration rate greatly boosts coexistence as compared with the situation where there is no migration. However, increase of the migration rate beyond a critical value leads to the complete dominance of the more efficient template type (homogeneous regime). In this case, we find a continuous phase transition separating the homogeneous and the coexistence regimes, with the order parameter vanishing linearly with the distance to the transition point.