A Mega Millions ticket sold in New York won $1 million and narrowly missed the $387 million jackpot, lottery officials say.