One sentence, four claims
Without special intent the main accent falls late, on the last content word before the closing verb. Put it anywhere else and you contradict a silent alternative: this word, not another one. Two things make the contrast audible: the accented syllable is louder, longer and higher, and everything after it drops low and flat.
Ich habe Anna das Buch gegeben.
[Ich habe Anna das BUCH gegeben ↘]
I gave Anna the book.
neutral: the accent where it falls anyway
Ich habe Anna das Buch gegeben.
[ICH ↘ habe Anna das Buch gegeben]
I was the one who gave Anna the book.
not someone else; the rest is low
Ich habe Anna das Buch gegeben.
[Ich habe ANna ↘ das Buch gegeben]
It was Anna I gave the book to.
not Paul
Ich habe Anna das Buch gegeben.
[Ich habe Anna das Buch geGEben ↘]
I gave Anna the book, I didn't just lend it.
the closing verb itself is the news
Stress the syllable that differs
When two words share most of their form, the accent goes to the part that makes the difference, even if that part is normally unstressed. A prefix like ver- is usually light, but in a contrast with the bare verb it carries the beat.
Wir wollen das Auto verkaufen, nicht kaufen.
[das Auto VERkaufen ↗ nicht KAUfen ↘]
We want to sell the car, not buy it.
normally verKAUfen
Ich packe die Koffer ein, nicht aus.
[die Koffer EIN ↗ nicht AUS ↘]
I'm packing the cases, not unpacking them.
Ich habe das gesagt, nicht geschrieben.
[Ich habe das geSAGT ↗ nicht geSCHRIEben ↘]
I said it, I didn't write it.
ge- is the same in both, so it stays light
Insisting on the truth: the auxiliary or doch
To insist that something really is the case, English uses do with stress: I DID lock it. Standard German has no such helper verb. It stresses the conjugated verb, or it adds a stressed doch when contradicting someone. Both are common; doch is stronger.
Ich hab die Tür abgeschlossen.
[Ich HAB ↘ die Tür abgeschlossen]
I did lock the door.
the auxiliary carries the insistence
Ich hab die Tür doch abgeschlossen!
[Ich hab die Tür DOCH ↘ abgeschlossen]
But I did lock the door!
contradicting a reproach
Das ist möglich, egal was die anderen sagen.
[Das IST ↘ möglich]
It IS possible, whatever the others say.
Two accents: rise, then fall
A sentence can carry two contrasts at once. The first accent, in position one, rises; the second, later in the sentence, falls. This rise-fall shape is called the hat contour. It can even change what a sentence means.
Alle Studenten haben nicht bestanden.
[Alle Studenten haben NICHT ↘ bestanden]
None of the students passed.
one accent: usually understood as nobody passed
Alle Studenten haben nicht bestanden.
[↗ ALle Studenten haben NICHT ↘ bestanden]
Not all of the students passed.
rise on alle, fall on nicht: some failed
Den Wein bezahle ich, das Essen zahlst du.
[Den ↗ WEIN bezahle ICH ↘]
I'll pay for the wine, you get the food.