If $\vec a$, $\vec b$, $\vec n$ are oriented like standard basis vectors $i,j,k$, then the shortest angle is counterclockwise. Otherwise, it is clockwise. This suggests the following algorithm:
1. Compute the triple product of $\vec a$, $\vec b$, $\vec n$, in this order.
2. If the triple product is positive, the answer is $\arccos \frac{\vec a\cdot\vec b }{|\vec a||\vec b|}$. Otherwise it is $2\pi- \arccos \frac{\vec a\cdot\vec b }{|\vec a||\vec b|}$.
(The triple product is zero only when the three vectors lie in the same planar, which is not the case here).