Generally speaking, the Preterite is used for actions in the past that are seen as completed. The Imperfect tense is used for past actions that did not have a definite beginning or a definite end.
The preterit (pretérito) is used in Spanish to answer the question What happened? On the other hand, you will often use the imperfect (imperfecto) if it answers the question What was going on when something else happened?
Generally, the preterit is used to relate events while the imperfect is used to describe what was going on in the past, states of being in the past, or past habits.
All this takes on special importance in narration of past actions when both tenses often occur in the same story. Narrating a story entails both describing a setting (habitual actions, atmosphere, places and people) and recounting a plot or a series of events, actions, changes of feelings or thoughts. In general, all stories have a well delineated plot line of events, the foreground, and a background of supporting details and description.
Some verbs like ser, poder, querer, saber, etc. tend to be in the imperfect when narrating the past, since they most likely describe a past state of being or condition. However, when these verbs occur in the preterit, they indicate a change of state or a change of condition and they can have different meanings.