We describe a Las Vegas algorithm for the principal ideal problem in matrix rings for , over maximal orders in the rational quaternion algebra ramified at and a prime number . Under plausible heuristic assumptions, the method has expected polynomial runtime. An implementation in SageMath shows that it runs very efficiently in practice, with compact output. Our main auxiliary result is a method for finding endomorphisms of superspecial abelian varieties (i.e., powers of supersingular elliptic curves) with a prescribed kernel.