My understanding is that the z-axis transformed by the matrix becomes the extrusion vector.
I would say: The z axis w.r.t. the actual extrusion space (i.e. those where the extrusion is performed) should be transformed into the extrusion axis in specification space (i.e. those where the demanded extrusion axis is specified), and the already generated 3D extruded shape should undergo the same transformation.
However, here is already a problem. Assume a square in the xy plane. Extrude it in z direction. Apply a rotation so that the z axis becomes the specified extrusion axis. The resulting shape will be a coboid, all angles between neighboring faces being 90 degree. Now think of the shape that would result if the same square is extruded along an axis titled by e.g. 45 degree in x direction. Those shape will be another one. To overcome this problem, one has to transform the square so that the orientation of the square relative to the extrusion axis is the same in this space as it was in the specification space. The transform applied, however, is actually the inverse of those where the OP is looking for. So it seems me that either the extrusion is not done correctly, or else the solution is indirectly already given. We need some more information on this.
This page also shows how to set up a matrix that rotates the extrusion from its original z-orientation towards a second vector on the plane formed by the two vectors.
Well, this solution is one possibility of infinitely many solutions; but it is one, correct.