The role of the goalkeeper in soccer is to protect the team's goal by preventing the opposing team from scoring. Goalkeepers are the last line of defense and are responsible for stopping shots on goal, organizing the defense, and distributing the ball to start counterattacks. They also communicate with their teammates to ensure proper positioning and defend set pieces effectively.