For weeks, Panama was shaken by its largest protest movement in decades as residents decried a mining contract given to a Canadian firm, saying it risked their sovereignty.