Core difference
了 (le) signals completion of a specific action at a specific moment. The sentence refers to a definite event. 过 (guò) signals that an action happened at least once in the speaker's past, without pinning it to a specific moment. 过 is the experiential aspect; 了 is the perfective aspect. When an English speaker says "I have been to Japan," they mean "at some point in my life" — that is 过. When they say "I went to Japan last year," they mean a specific past event — that is 了.
Sentence structure
Both markers attach directly after the verb. 我吃了饭 vs 我吃过日本料理. The key difference is that sentences with 了 often specify the time or the result; sentences with 过 often focus on the lifetime-experience quality. 了 sentences readily accept a specific object (我看了这本书 — I read this book); 过 sentences often take a generic category (我看过日本电影 — I have seen Japanese movies).
我去了北京。/我去过北京。
Wǒ qù le Běijīng. / Wǒ qù guò Běijīng.
I went to Beijing (recent, specific trip). / I have been to Beijing (at some point in my life).
Time expressions change which to use
Specific past time phrases (昨天, 去年, 上周) pair with 了. Generic or lifetime phrases (以前, 从小, 有一次) pair with 过. If the sentence answers "when?" with a specific moment, use 了. If it answers "have you ever?" or "at some point," use 过.
昨天我吃了鱼。/我以前吃过鱼。
Zuótiān wǒ chī le yú. / Wǒ yǐqián chī guò yú.
Yesterday I ate fish. / I have eaten fish before.
Negation
Negating 了 uses 没: 我没吃饭 (I did not eat). Negating 过 uses 没...过: 我没去过北京 (I have never been to Beijing). Note that the 过 stays in negated sentences — you cannot drop it. The negation patterns show the durative meaning: "have never" matches 没...过 perfectly.
Questions
了 questions use 了 + 吗 or 了 + 没有: 你吃了吗?/你吃了没有?(Did you eat?). 过 questions use 过 + 吗 or 过 + 没有: 你去过北京吗?/你去过北京没有?(Have you been to Beijing?). The 没有 forms are slightly more common in spoken Mandarin for 过 questions.
Advanced: sentences with both
You can stack 了 and 过 in the same sentence when you want to emphasise that a past experience did indeed happen and is now complete. 我去过北京了 can be read as "I have already been to Beijing (and that trip is done)" — the final 了 adds sentence-final "already" nuance. This is a nuance pattern; you will rarely need it for HSK, but it appears in native speech.