William's active military career lasted more than seven years, first in the Army and then in the Royal Air Force. Air Chief Marshal Andrew Pulford said William had been an important part of the Royal Air Force's search-and-rescue force for the past three years.
"Throughout his tour his airmanship, often in the most demanding of conditions, has contributed directly to saving lives in the mountains of North Wales and from the ravages of the Irish Sea," said Air Chief Marshal Sir Andrew Pulford in a statement. "He has earned the respect of all who have worked with him as a highly professional and competent pilot."
William completed 1,301 flying hours and participated in 156 search-and-rescue operations, helping to rescue 149 people.
The prince completed his final shift on Tuesday at 9:30 a.m. after conducting a routine training flight.
Prince William, his wife Kate and their 2-month-old son, Prince George, are expected to move into their official residence at Kensington Palace in the next few weeks. They had been living in a rented home in Anglesey.
"He will expand his work in the field of conservation, particularly in respect of endangered species," the palace said in a statement.
William on Thursday teamed up with sports stars David Beckham and Yao Ming to record public service announcements designed to reduce demand for rhino horn and ivory.
The Associated Press contributed to this report.