Agnew helps Ireland avoid relegation