You did the wrong thing. Black bears will often charge as a form of intimidating. When they do you should stand your ground and charge back at them. If you run, they know you are scared and scared means you are prey. They are quite capable of climbing up a tree after you.
Yosemite bears just love to scare campers. It is a great way to get the campers' food.