What happens if you don't get tenure?
In my experience (in math, in the US), no you cannot remain in your current position (for long). While tenure is historically a means of protection for faculty from political forces, and thus a tool to provide academic freedom, pre-tenure periods often function as a sort of long-term provisional hiring period to make sure you're right for the university/department and getting tenure is sort of stamp of certification of your worth to the department and university. So if you fail to get tenure, the reason is typically because someone decides you're not performing well enough in your current position.
That said, the university will typically give you another year in your current position which gives you time to look for jobs elsewhere. People who don't get tenure usually move somewhere else, or have trouble getting another job.
Note: Sometimes people go up for tenure early (before the specified date in your contract). I don't know what the standards are for consequences of not getting tenure then--when I've seen people go up early, they got tenure.
At most institutions whose procedures I'm aware of, you only get one chance at a tenure application at a given university. If you are not granted tenure, there are usually provisions for how long you can stay—usually until the expiration of your existing contract, which typically amounts to until the end of the academic year following the denial of tenure. Following that, you have to move somewhere else, whether it's an academic position at another institution or a position outside of academia.
Here is how it works at my US institution. (I know that some other US institutions have similar systems, and my impression is that this is in fact typical in the US.)
When hired as an Assistant Professor, the job offer includes a mandatory date for latest possible tenure consideration, normally in the sixth year of the position. (Ninth year for clinical faculty in professional schools.) An Assistant Professor can apply for tenure and promotion in any year before that; if they are unsuccessful they can remain in the position and apply for tenure again, up until that latest possible date. If they are unsuccessful at getting tenure at the latest possible date, they get one more year in the position then have to leave.
So in theory, an Assistant Professor could apply for tenure over and over again through that six-year period. In practice, that would be a terrible idea. Most people apply for tenure only once at a given institution, and leave for another institution if they're unsuccessful. I don't believe I've personally ever heard of someone applying more than twice for tenure at a given institution.