Things don't always work out this way though. If you publish a scientific paper that reports an interesting result, it can permanently help your career even if it is later proved to be wrong. It just needs to be believed for about 10 years or so - you'll extract most of the career advancement possible from the paper during that time. When the paper is debunked, as long as there is no evidence of fraud, you'll still have tenure, you'll still be the PI on projects you have started after the paper, you'll still have your network of collaborators who won't shun you if it looks like you made an honest mistake years ago.
I've seen the above happen, and it can be caused by a perverse fact one of my mentors told me in grad school: "Bad data almost always looks interesting." Cold fusion started out as bad data, and looked very interesting. Those faster-than-light neutrinos that were in the news several years ago were bad data. When I was a kid in the 1960s, there were numerous reports of exoplanet detections - all were bad data. Etc.