The operation of a transistor is entirely based on a class of materials known as semiconductors, which chemists and engineers have known about since the mid-1800s. In 1833, Michael Faraday noted that silver sulfide decreased in electrical resistance when heated (metals usually increase in resistance when heated). In 1880, Alexander Graham Bell used selenium — a semiconductor that produces electricity when it’s struck by light — to transmit sound over a distance with his Photophone device.
Real analysis of semiconductors didn’t really begin until the 1920s, though, when scientists tried to work out why and how there was a class of materials that appeared to be metals, but behaved very differently than normal metals. With World War II, and the advent of radar and other radio technologies, semiconductors started to become very serious business. It wasn’t really until Bell Labs started researching semiconductors after WW2, though, that we finally started to learn about and control the properties of semiconductors.

A diagram showing the first germanium amplifier, using water as an electrolyte. When a potential is applied by the wire on the left, increased current flows across the right-hand circuit.
In specific, Walter Brattain, John Bardeen, and William Shockley of Bell Labs decided to investigate the bulk and surface properties of silicon and germanium. Through a series of experiments, the researchers discovered that by applying a small amount of electricity to the surface of a piece of germanium, it could increase the flow of electricity through a second circuit that was also connected to the piece of germanium — in other words, an amplifier. The earliest germanium amplifiers used liquid electrolytes which would dry up, or were only capable of switching at low frequencies. Then, on December 23 1947, gold contacts were used instead of an electrolyte — and thus the first transistor was born.