I assume you had what is called a Arbeitszeitkonto (work time accounting) - meaning you were allowed to vary the amount of time you worked each day, and your work time was recorded on a time sheet, allowing you to "gain" or "lose" hours each day compared to your regular work time.
In that case, you may have to pay back the money.
There is a long article on this topic here:
Negativer Saldos auf dem Arbeitszeitkonto – und seine Verrechnung beim Ausscheiden (Negative balance on the working time account - and its consideration when leaving employment).
The short rule is:
- if you worked less because you wanted to, you may have to make up the deficit
- if you worked less because you were told to, you don't (§615 BGB - note however that this can be changed in the employment contract)
To actually make the employee make up the "missing" time, the employer usually has to prove the employee asked for time off.
In addition to that, even if the employer is owed missing work time, they cannot necessarily take back salary already paid. Usually they are only allowed to ask the employee to work extra, or cut the next salary (because the salary paid while the employee worked less is considered an advance payment).
Unless it is explicitly mentioned in the contract, they probably cannot take back money already paid, and even if it is mentioned, it might not be valid.
Finally, rights and obligations from an employment contract become unenforceable after the period of prescription (Verjährungsfrist) has passed. The limit is three years by default, but can be shortened in the contract, down to three months (which is not uncommon). In that case, claims arising from the contract (such as taking back wages) will expire after three months - check if this applies.