Riga FC edged FC Ararat-Armenia 3-2 in a thrilling Champions League qualifier, with a last-minute Ramires penalty sealing the victory.