A pharmacy student who repeatedly stabbed a passer-by with a machete has been convicted in a Sydney court of carrying out a terrorist act.

Ihsas Khan had pleaded not guilty in the New South Wales state Supreme Court on the grounds of mental illness when he attacked Wayne Greenhalgh in the Sydney suburb of Minto in 2016.

Khan was found guilty on Thursday during his sixth trial by a jury which rejected his mental illness defense.

Four previous trials were aborted and the fifth jury could not reach a verdict.

A judge will hear sentencing submissions on May 23. Khan faces a possible maximum sentence of life in prison.

Greenhalgh received injuries to his right arm, left hand, face and lungs. He was forced to take four months off work.