In some ways, solar panels work like batteries and thermocouples. Two dissimilar conductors are placed together, and electrons move from the one that holds them loosely, to the one that holds them tighter.
There are many types of solar cell materials, and not all of them work in the same way. In the simplest ones, a photon of light knocks an electron off of a metal, and that electron flies off to another conductor, then goes through a circuit to get back to the original metal plate.
But most solar cells these days use semiconductor materials in what is called a p-n junction. In a silicon solar cell, the two sides of the p-n junction are made of silicon. A small amount of phosphorus is added to one side, to make the N material. A small amount of boron is added to the other side to make the P material.
Phosphorus has one more outer electron than silicon does. Boron has one less. The electron from the phosphorus becomes a conduction electron, allowing electric current to flow in the material. In the P material, the missing electron from the boron creates a “hole”. An electron from silicon can move into the hole, leaving a hole behind. In this way, the holes can appear to move around.
When the two are put together to form a p-n junction, the extra phosphorus electrons in the n-type silicon are attracted to the holes left by the boron in the p-type silicon. This creates a voltage gradient in the cell.
When a photon of light hits the semiconductor, an electron is excited and becomes a conduction electron. It moves along the voltage gradient from the negative side of the cell to the positive side. The hole it created when it left the silicon atom moves towards the positive side, just as a bubble of air floats to the top of water.
When the solar cell is connected to a meter or to a light bulb, the electrons can flow through the wires to get back to the other side of the p-n junction, filling in the holes, so the whole process can start over again.