This is more common than it looks like — I know 2-3 such cases of folks who had to leave, then published and then regained their footing quickly (3-4 years) . Many committees are backward looking and will not count at all a series of prestigious RRs.
I was turned down for tenure too. It was painful - I had to uproot the family and move and my wife had to quit her job. Two years later, three of the papers I had completed while working at my original employer came out in top 5's and then other ones started rolling in. So 5 years down the line I had a job in a better department than the one that turned me down for tenure. The real cost was on the family (which eventually broke up) and I blame my tenure committee for that - they should have said "wait a year, those three papers are great" but they were entirely backward looking and probably unable to see the quality of the papers. I learned a lot, it was costly but avoidable, and I now try to be helpful to juniors to make sure it doesn't happen to them.