Flanagan upsets field to win 4x100m relay