We construct Goppa type sum-rank codes over \(\mathbb {F}_q\) with the matrix size \(n \times n\) , directly from Goppa codes or extended Goppa codes over \(\mathbb {F}_{q^n}\) in the Hamming metric. Lower bounds on dimensions and minimum sum-rank distances of Goppa type sum-rank codes are proved. The Goppa type sum-rank codes offer great flexibility in block length and dimension while maintaining strong error-correcting capability compared to the best known sum-rank codes. Furthermore, we construct numerous distance-optimal binary sum-rank codes with variable block length and minimum sum-rank distance four.