Finn Azaz and Matt Doherty scored first-half headers as the Republic of Ireland battled back to beat Bulgaria 2-1 in the first leg of their Nations League play-off.