You are looking for a quaternion q, such that qjq'=n, where n is the imaginary unit quaternion representing the axis of the object. This has a standard solution in terms of the product jn, essentially the square root.
If
jn=c+s*e, e imaginary unit, c²+s²=1, s>=0
then
q = sqrt(0.5*(1+c)) + sqrt(0.5*(1-c))*e
so compute
p=j*n // condition is n is imaginary unit
c=real(p)
e=imag(p)
s=abs(e)
if(s>0) e=e/s else e=j
s=sqrt(0.5*(1-c))
c=sqrt(0.5*(1+c))
q=c+s*e