They say he was inspired by the Islamic State (IS) group.
Officers say the attacker repeatedly stabbed a 59-year-old man in a suburban park and then tried to stab a policeman.
A large knife has been seized from the accused,  who will appear in court later on Sunday.
The victim, who was reportedly walking his dog in the park, suffered injuries to his body and hands, and remains in hospital in a serious condition.
Although the authorities say they believe the attacker was inspired by IS, they do not think he has close ties to any extremist organisation.
"This is the new face of terrorism. This is the new face of what we deal with," New South Wales state police Deputy Commissioner Catherine Burn said.
Timeline: Australia's terror threat
The arrest comes two days after a teenage boy was charged with making threats at Sydney Opera House.
Prime Minister Malcolm Turnbull said last week the threat of a terror attack in the nation was "real" after an IS call to followers to target prominent Australian locations.
Police in Australia have charged a 22-year-old man with committing a terrorist act and attempted murder in southwest Sydney.