Quick answer
preterite (hablé, comí) = a finished event, the thing that happened.
imperfect (hablaba, comía) = background, habit, ongoing state, "used to" or "was -ing".
A story runs on both: the imperfect paints the scene, the preterite moves the plot.
Side by side
Memory trick
Ask: am I telling what happened next, or what things were like? "What happened next" is preterite. "What it was like" is imperfect.
Typical mistakes
Ayer estaba muy cansado y me acostaba temprano.
Ayer estaba muy cansado y me acosté temprano.
Being tired is the background state (imperfect), but going to bed is the event that happened (preterite). Learners often put both in the same tense.
Cuando era joven, fui a la playa cada verano.
Cuando era joven, iba a la playa cada verano.
"Cada verano" marks a repeated habit with no endpoint, which is exactly what the imperfect is for.
Check yourself
Fill in: "Mientras ella ___ la cena, llegaron los invitados."