Most legendaries are going to flee first chance they have. The best option is to use a master ball at the start of battle. If you don't have one, you need to put the pokemon to sleep and hope you have the first move to do so. Otherwise, it's going to flee and continue fleeing.
On the off chance when a legendary does stick around to attack once before it flees, use that to your advantage to give as much damage as you can. There's also a move like Mean Look which will also help keep a pokemon from fleeing.
On the off chance when a legendary does stick around to attack once before it flees, use that to your advantage to give as much damage as you can. There's also a move like Mean Look which will also help keep a pokemon from fleeing.