A transistor functions by controlling the flow of electrical current between its three terminals: the collector, base, and emitter. By applying a small current or voltage to the base terminal, the transistor can amplify or switch the flow of current between the other two terminals. It acts as a switch or an amplifier in electronic circuits, allowing for the control of larger currents or voltages based on the input signal at the base terminal.