A quaternion unit gain graph (or \(U(\mathbb {Q})\) -gain graph) is defined as a triple \(\Phi =(G,U(\mathbb {Q}),\varphi )\) (or \(\widetilde{G}\) for short) consisting of an underlying graph G, the quaternion unit circle group \(U(\mathbb {Q})=\{q\in \mathbb {Q}: |q|=1\}\) and gain function \(\varphi :E(G)\rightarrow U(\mathbb {Q})\) , such that \(\varphi (e_{ij})=\varphi (e_{ji})^{-1}=\overline{\varphi (e_{ji})}\) . The adjacency matrix of \(\Phi \) is denoted by \(A(\Phi )\) and the left row rank of \(\Phi \) is denoted by \(r(\Phi )\) . If \(\Phi \) has at least one cycle, then the length of the shortest cycle in \(\Phi \) is the girth of \(\Phi \) , denoted by g. Khan and Van Dam (A bound on the girth of quaternion unit gain graphs in terms of the rank, in http://arxiv.org/abs/2411.19057, 2024) proved that \(r(\Phi )\ge g-2\) for \(\Phi \) and characterized \(U(\mathbb {Q})\) -gain graphs satisfying \(r(\Phi )=g-2\) . In this paper, we extend the result of Khan and Van Dam (A bound on the girth of quaternion unit gain graphs in terms of the rank, http://arxiv.org/abs/2411.19057, 2024) and characterize \(U(\mathbb {Q})\) -gain graphs of rank \(g-1\) or g. Moreover, we characterize all quaternion unit gain graphs with rank 2. The results will generalize the corresponding results of simple graphs (Zhou et al. in Linear algebra Appl 630:56–68, 2021), signed graphs (Wu et al. in Linear algebra Appl 651:90–115, 2022), and complex unit gain graphs (Khan in Linear algebra Appl 688:232–243, 2024).