A natural 20 is automatically a hit, and threatens to be a critical, then you re-roll for confirming the critical (for which it has to be higher than the enemies AC to a maximum of 20).
Now if you're wielding a keen rapier you threaten a critical anywhere between 15-20 on the attack roll. What if that wouldn't be a hit though?
For example you roll a 15, attack bonuses are +4, enemies AC is 20. If it was a normal roll that would definitively be a miss, but it was a potentially critical roll; yet it wasn't a natural 20. Does it hit?
No, it does not hit. From the Pathfinder Reference Document (emphasis mine):
To threaten a critical hit with that rapier, you need to roll 15 or above and hit normally.