It worked by simple pattern recognition and substitution of key words into canned phrases. It was so convincing, however, that there are many anecdotes about people becoming very emotionally caught up in dealing with ELIZA. All this was due to people's tendency to attach to words meanings which the computer never put there.
This became an important motivation for J. Weizenbaum to write his book Computer Power and Human Reason. From Judgment to Calculation, in which he explains the limits of computers, as he wants to make clear in people's minds that the anthropomorphic views of computers are just a reduction of the human being and any lifeform for that matter.