Moving one bone to another

I need to align one bone from the armature 1 to another bone in the armature 2.
So I multiply the world_matrix of the armature 1 to the inverted matrix and to the world_matrix of the armature 2.
It works, while bones in both armatures have the same transform.
If in edit mode I rotate the bone in the armature 2, and try to execute the same script I got not the proper result.
I try to multiply to the local_matrix of the bone in the armature 2 but the result is not proper again (it’s on the right of the image, the blue bone was rotated in the edit mode).
Why I got this result and how to properly align bone along another bone in a different armature?

Thanks to Arthur Shapiro!

The solution is

a1.matrix_world = a2.matrix_world
a1.pose.bones[0].matrix = a2.pose.bones[0].matrix

But I don’t understand why it works… )