Sri Lanka has voted in an unexpectedly close election that pits President Mahinda Rajapaksa against one of his former allies.…