St Mirren held off a valiant second-half comeback to revive their top-six ambitions with a thrilling 3-2 victory at Hibernian.