A turbine connected to a generator produces power inside a dam.
Diagram of a hydroelectric generator is courtesy of U.S. Army Corps of Engineers.
As to how this generator works, the Corps of Engineers explains it this way:
"A hydraulic turbine converts the energy of flowing water into mechanical energy. A hydroelectric generator converts this mechanical energy into electricity. The operation of a generator is based on the principles discovered by Faraday. He found that when a magnet is moved past a conductor, it causes electricity to flow. In a large generator, electromagnets are made by circulating direct current through loops of wire wound around stacks of magnetic steel laminations. These are called field poles, and are mounted on the perimeter of the rotor. The rotor is attached to the turbine shaft, and rotates at a fixed speed. When the rotor turns, it causes the field poles (the electromagnets) to move past the conductors mounted in the stator. This, in turn, causes electricity to flow and a voltage to develop at the generator output terminals."