Solar cells convert sunlight into electricity through the photovoltaic effect, where semiconducting materials like silicon absorb photons from the sunlight and generate an electric current. This electric current can then be used to power electrical devices or stored in batteries for later use.