The official Mega Millions website states it quite clearly: "Visitors to the United States are always welcome to purchase tickets for our game from an American lottery retailer while they are visiting this country. You do not need to be a resident to win."
The Mega-Sena is the largest lottery in Brazil, organised by the Caixa Econmica Federal bank since March 1996.