Lionel Messi was controversially sent off as Argentina beat Chile 2-1 to win the Copa America third-place play-off in Sao Paulo.