We consider the refinement of estimates of invariant (or deflating) subspaces for a large and sparse real matrix (or pencil) in $$\mathbb {R}^{n \times n}$$ R n × n , through some (generalized) nonsymmetric algebraic Riccati equations or their associated (generalized) Sylvester equations via Newton’s method. The crux of the method is the inversion of some well-conditioned unstructured matrices via the efficient and stable inversion of the associated structured but near-singular matrices. All computations have complexity proportional to $$n$$ n , under appropriate assumptions, as illustrated by several numerical examples.