The Predetermined Minimum Scale
In general, at least in the US and according to my experience with a few institutions, grading often goes like this:
The professor sets up a grading scale (generally percentage to letter grade conversion) and puts it in their course syllabus at the beginning of the semester. This commonly goes something like 94% >= A, 90% = A-, 87% = B+ ... < 60% = F.
The syllabus also includes an outline of weighting of grades - for instance 10% "attendance and participation", 40% assignments, 50% midterm + final.
These guidelines as noted in the syllabus reflect a "guaranteed minimum grade". This means that if you get 90% in this course you are guaranteed at least an A-. However, this also means that the professor generally reserves the right to adjust grades upwards, especially in borderline cases. If you got a 93.7% and participated actively in class, they might bump it up to an A solely at their discretion!
In this scheme, students are protected against wanton harshness, like a professor suddenly decides the final wasn't hard enough and so suddenly anyone with less than a 95% gets a B.
Please be aware this is not the only grading system!
Forced Curve Grading
Another system uses what is sometimes called a "forced curve", and is designed such that - for instance - only 10% of students can get an A of any kind. It doesn't matter what your score is - just that your relative ranking is compared to other classmates that semester. I'm told the Airforce Academy uses this system extensively (or at least use to), among other institutions and sometimes even individual professors choose this system.
So you can theoretically bomb the final and get a miserable score, and if everyone else did too then your grade might still be excellent.
Hybrid Grading Systems
Bespoke systems implemented by various professors abound across the USA, which is part of the reason most graduate schools take GPA with at least a few grains of salt (it is understood that a 4.0 in one program might be equivalent to a 3.5 in another, to say nothing of whether or not a 4.0 student in one program might be otherwise inferior to a 3.5 student in the same program due to different student focus).
One system I've found somewhat common is using the predetermined grading scale, setting the scale strict as shown above, but then giving very difficult exams where they note that even they themselves would not be able to score 100% if they didn't have their answer key at hand. In these classes getting even a 90% is truly difficult. The goal is perhaps to be more discriminating, and a score of 100% isn't very informative in this outlook. I found math professors much more likely to fall into this category!
So what the professors do is at the end of the semester they plot out all the grades (in a histogram, scatter plot, or sorted-by-grade spreadsheet), and then take a look. They find some sort of 'gap' in the actual grades, and decide anyone above that gap gets the maximum score of A. The next 'segment' gets the next highest grade, on down to the end. No one gets bumped down to a lower grade, but many students can/do get bumped up.
Discounting Aberrant Grades
Many professors also compare the grades on a final exam to scores in the rest of the course, and adjust grades up in certain cases. One example is if you did well all semester long, then somehow did poorly on the final. If this seems like a weird aberration and you participated and clearly worked hard in class, sometimes a professor will think the grade is a poor reflection of your understanding of the material and will lower its weight - effectively giving you a better grade than your final would indicate.
Other professors look at the final as the most important/difficult test, and if you did significantly better on the final than in the rest of the class they will assume you must have learned the material (or you wouldn't have done so well on the hardest test!) and bump your grade up - effectively discounting your earlier less-spectacular grades.
Of course, some professors do none of this. Some give lots of extra credit, or "easy A" assignments so you just have to turn something in, etc. In the USA professors usually have a tremendous amount of independence in determining grades, and they often just have to have a sensible system they can defend if 'challenged'. But some don't really care and pretty much do what they want. YMMV.
Your Specific Case
In your specific case of wondering how you got a good grade even though you thought you bombed the final, it's possible you did not actually bomb the final - and it's also possible you did and got 'curved' up, or the professor discounted your grade on the final because you otherwise did so well in the course.
If you are really concerned or wondering, you can generally ask the professor or meet with them to share your concern that you bombed the final, etc. I personally wouldn't "look a gift horse in the mouth" (question someone who graded you kindly), but if you really feel uncomfortable with the grade then by all means you can politely ask to go over the final with the professor or discuss your grade more generally.
One final note- I have known a number of people exhibit a mentality I like to call "reverse paranoia": the belief that people are secretly out to help you even though you don't deserve it! It's very possible you did better than you think or even that you earned the grade you got (I know, crazy right?), and the professor just gave you the grade you deserved. This may or may not be related to the impostor syndrome, or just a past experiences that were negative. But this is just a pet theory/observation of mine!