Lionel Messi scored twice as Barcelona became the second team to reach 6,000 La Liga goals in the competition's history.