Unfortunately, that's not always the case. You may be the perfect candidate on paper possessing every skill a job requires, yet you go no further than the first interview. People hire people they like. This might seem ridiculously obvious, but since the boss will need to spend a big chunk of time with you, he or she will want to like you. There is almost no chance that a boss will hire you if he just don't like you.
People hire people who are like everyone else there.
That could mean like everyone at the company, or simply like everyone in the department. He doesn't fit in here at all. You get the point. You can attempt to bridge the like-ability gap. Do your homework on the interviewer and try to find mutual interests to discuss.