Models of the convergence of opinion in social systems have been the subject of considerable recent attention in the physics literature. These models divide into two classes, those in which individuals form their beliefs based on the opinions of their neighbors in a social network of personal acquaintances, and those in which, conversely, network connections form between individuals of similar beliefs. While both of these processes can give rise to realistic levels of agreement between acquaintances, practical experience suggests that opinion formation in the real world is not a result of one process or the other, but a combination of the two. Here we present a simple model of this combination, with a single parameter controlling the balance of the two processes. We find that the model undergoes a continuous phase transition as this parameter is varied, from a regime in which opinions are arbitrarily diverse to one in which most individuals hold the same opinion.