That is a complicated question. Wikipedia has a good article on the subject so my suggestion is to check it out.

http://en.wikipedia.org/wiki/Game_engine