The working principle is the same in both systems.
Light makes electrons in silicon 'jiggle about' and the silicon is etched in a way that the jiggling makes those electrons move in the same direction. This process is the same as occurs in solar panels.
When the image is 'read' from the sensor, each pixel has the charge measured (how this happens differs between the two) using an analogue>digital (AD) converter and those values represent the light levels which make up the image.
What splits CCD and CMOS are that the materials and construction differ. That has a knock-on effect on how they're used in practice in photography. CMOS sensors can be baked at just about any chip foundry where CCD's require a tailored VLSI process that can only make CCD chips.
Both systems have traits which give them some on-paper advantage. Excepting some specific tasks (astrophotography for example) it's hard to say that currently either one is actually better than the other. CMOS sensors are cheaper/easier to produce, benefit more readily from other advances in chip making, allow for readouts to occur in parallel and use less power. CCD leaves more area available for the photosite and better noise characteristics but must read line-by-line which slows processing. Currently the chip advances mean CMOS has the edge in photography today and is likely to for the time being.