Pakistan beat India by three runs, qualify for final