Pam was a loser. Roy was a loser, and Pam was Roy's doormat.
Jim was a winner, but he threw away his place in society so that he could listen to "Dunder Mifflin, this is Pam" for years.
When he finally worked up the courage to make a move, Pam shot him down, so he moved on with his life and landed Karen, a winner like him, but "a winner" was never what he really wanted.
But fate wouldn't let Jim move on with his life, and he and Karen were jammed into the office with Pam, who had changed her mind, and now wanted Jim to dump Karen, like she dumped Roy. Once Jim did that (Karen never really stood a chance), Jim and Pam's storyline was basically done.
Karen was objectively better than Pam, but Jim didn't make the wrong choice.