Interesting subject - we have active cougar activity on our property and neighbor property right now. Keep in mind - cougars and wolves will track and follow you. Sudden movements - like kids tend to have will make cougars more likely to attack - like a kitty playing with a live mouse.
No sudden movements if you find yourself off your horse, like others said, make yourself bigger, don't move, and stare them in the eye. Even if hungry, cougars are careful about not getting hurt. If it is far away, slowly move back toward home or cover, and find a big stick or rocks. Since I know cougar are around here, and we are in the US, I would be carrying a gun.
If a cougar is close and looks ready to strike (kind of like a kitty ready to pounce), make a ton of noise (you will be living on adrenaline at that point anyway), and fight like heck - aim for the eyes or nose, hitting it with whatever you can find. Never turn your back.
Cougars are sprinters, not necessarily long distance runners - that is why deer can get away, but I sure wouldn't recommend running away from one.
I don't know if there is necessarily anything you did wrong in the moment but I personally would never get off my horse - just turn around and keep moving home. A couple friends had a similar encounter when a baby cougar crossed the trail, and then saw mama was watching from a hill above - they turned around, and mama followed them all the way back to the main road. From what I understand, their horses were nuts too.
I know people around here who use cougar "fur" to work on desensitizing their horses at home. I can't recommend where you would find that but maybe a taxidermist or hunting club.