Alvarez had pleaded guilty to violating a 2006 law that was adopted with the nation at war in Afghanistan and Iraq and aimed at people making phony claims of heroism in battle. The court, in a judgment written by Justice Anthony Kennedy, ordered that his conviction be thrown out.