The ref was playing passive-offsides here, BUT he incorrectly interpreted the application of it. Cocis makes an absolutely beautiful run that isn't offside right next to Gilberto who is offsides. Gilberto starts his run at the 6 second mark and is clearly offsides - that should have been when the whistle blew. Gilberto actually starts making a run to receive the pass and then stops when he realizes he's already offside; he was in perfect position to play the ball, which is what the defender thought was happening, until he held back at the end.