Gilani made the remarks during a meeting with visiting German Defence Minister Thomas de Maiziere. The two leaders discussed defence and military cooperation, the war on terror and regional and international issues, officials said.
"A political solution was the only durable solution because it carries the sanction and support of the people and their ownership, which offers the best guarantee for the longevity of peace," Gilani was quoted as saying in a statement issued by his office.
Pakistan is committed to supporting an "Afghan-led and Afghan-owned peace process" in Afghanistan because it wants to see the neighbouring nation as an independent, peaceful and prosperous country, he said.
Afghan President Hamid Karzai had recently appealed to Pakistan to ask all Taliban factions to cooperate in the reconciliation process and Islamabad had obliged by issuing a statement, Gilani said.
At the same time, Pakistan attaches "great importance" to its ties with the US and new rules of engagement will be framed soon with the approval of parliament, he told the German minister.