This type of er is hardly different from the previous type. It comes from ervan, meaning 'of it' or 'of them'.
Because 'it' is combined with a preposition, we use er instead. At some point, the Dutch decided to drop the postposition van, leaving us with a bare er. Note that the omission of van only applies to er, not to hier or daar.
|He had eaten three (of them).
We do not have to omit van:
|He had eaten three of them.