File- NATO Secretary General Jens Stoltenberg during a media conference after the meeting of NATO foreign ministers in Oslo, Norway, Thursday, June 1, 2023. AP
"Most wars last longer than expected when they first begin," Stoltenberg said in an interview with Germany's Funke media group.
"Therefore we must prepare ourselves for a long war in Ukraine."
The conflict began in February, 2022 when Moscow sent its forces into Ukraine, bringing war back to Europe for the first time in decades.
Kyiv launched its counteroffensive in June, pushing back against entrenched Russian positions in the south and east, but it has made limited gains.
"We are all wishing for a quick peace," said Stoltenberg.
"But at the same time we must recognise: if President (Volodymyr) Zelensky and the Ukrainians stop fighting, their country will no longer exist.
"If President (Vladimir) Putin and Russia lay down their weapons, we will have peace."
On Ukraine's ambitions to join the alliance, Stoltenberg said: "There is no doubt that Ukraine will eventually be in NATO."
Kyiv had "moved closer to NATO" at a summit of the alliance in July, he said.
"When this war ends, we need security guarantees for Ukraine. Otherwise, history could repeat itself," he added.
At the July summit in Vilnius, NATO leaders agreed that Ukraine could join the alliance once certain conditions are met, and US and German officials made it clear that these would include Kyiv carrying out reforms to protect democracy and the rule of law.