In the sentence "Ich begegnete einem alten Freund in Berlin", why do we use "einem" instead of "einen"? The sentence translates to "I met an old friend in Berlin". Isn't "an old friend" the direct object? Why do we use the dative "einem" instead of the accusative "einen"?
There is a broad rule of thumb to translate English direct objects to German Akkusativ objects and English indirect objects to German Dativ objects, but it's no more than that, a rule of thumb. There are a lot of exceptions to this rule.
Every verb, in English and in German, has its own set of objects that it can go with. Good dictionaries point out the possible objects and their case.
jemandem begegnen - to come across someone
Begegnen just goes with a Dativ object. The reason is in its history. It basically developed from a verb that had to do with "entgegen" (towards), a preposition that goes with Dativ.
In German you not only have to learn for every noun which gender it has, you also have to learn for every verb in which case it wants to have its objects.
When you look in any German grammar book, you NEVER will find the terms »direct object« and »indirect object«. These are categories that maybe exist in other languages, but they are NOT part of German grammar. So, please don't use this concept. It's misleading. You might get good results in 90% or maybe even 95% of all sentences, but that is not enough to learn proper German.
Do it, like we native speakers did when we learned our own language. We learned for every noun separately which gender it has and we learned for every verb and every preposition separately which grammatical case it's objects need. We learned by listening to other native speakers (parents and people in the neighborhood).
Have a look at the Wiktionary page for »begegnen«. There is a section »Bedeutung« (meaning) and there you can read, that you only can use it with dative case. - I'm sorry, this information about the cases of objects is given very sporadic and inconsistent in Wiktionary, and for most of the verbs you won't find explicit informations. But you always will find examples, and these examples might help you.
Here is a list of German verbs that need dative case: Verben mit einer Dativ-Ergänzung