"We strongly condemn this malicious terrorist act that targets Yemen's security, stability and national peace and extend out condolences to the families of the victims," a Turkish Foreign Ministry statement said on Tuesday.
Major-General Nasser Mahdi Farid, chief of staff for Yemen's central military region, was killed along with 16 other soldiers and officers in the ambush, which took place on Saturday while an army patrol inspected a pipeline in Wadi Obaida area of oil-producing Maarib province. It was one of the deadliest attacks by al-Qaeda in recent months.
The attackers were probably militants linked to al-Qaeda, said the official, who did not want to be identified.
Ankara said it will continue to support efforts to complete the transition period in Yemen with success. It added that Turkey will continue to stand by the Yemeni people in this transition process.
Yemen has struggled to restore normality since President Abd-Rabbu Mansour Hadi was elected in February following a year of protests that forced his predecessor Ali Abdullah Saleh to step down after 33 years in power.
The return of stability is a priority for the United States, Turkey and their Gulf allies because of Yemen's strategic position next to top oil exporter Saudi Arabia and major shipping lanes, and because it is home to a major wing of al-Qaeda.
Al Qaeda in the Arabian Peninsula has made its base in Yemen, and took advantage of the chaos last year in the run-up to and aftermath of Saleh stepping down, even taking over entire towns and areas in the south.
The group has mounted operations in neighbouring Saudi Arabia as well as attempting attacks against the United States, which has stepped up attacks by unmanned aircraft this year.
In June, the commander of military forces in the south of Yemen was killed by a suicide bomber in the port city of Aden.