(CNN) -- A U.S. military dog whose handler and best friend was killed in Iraq got a new assignment on Friday -- retirement with the late Marine's family.
Marine Cpl. Dustin Lee, slain in Iraq in March, with his dog, Lex, who is going to live with Lee's family.
It took the family months of lobbying to get the adoption approved by the military.
Lex was beside Cpl. Dustin Lee when Lee was killed in a mortar attack in Falluja.
In spite of his injuries, the dog didn't want to leave Lee's side after the attack, according to the Marine's father. Other Marines reportedly had to pull the dog away from the young man's body so medics could reach him. Watch Lex demonstrate his talents »
Lex attended Lee's funeral in March, playing games with the 20-year-old Marine's younger brother on the sidelines.
Although some shrapnel remains in his body, Lex recovered from his wounds and returned to duty at the Marine Corps Logistics Base in Albany, Georgia.
Friday, the 8-year-old bomb-sniffing German shepherd was turned over to Lee's family to live out the rest of his life in Quitman, Mississippi.
"This is to certify that military working dog Lex, having served faithfully and honorably, was discharged from the United States Marine Corps on this 21st day of December 2007," a Marine read at a ceremony interrupted by occasional barks.
Afterward, Jerome Lee, Dustin Lee's father, crouched down and shook Lex's paw.
Lex seemed oblivious to his 15 minutes of fame as he lay at the feet of a Marine during most of the ceremony.
Jerome Lee had lobbied hard for months to adopt the dog. Marine officials initially told Lee that it would be no problem to get the dog. But persuading the service to give up Lex before the dog's mandatory retirement at age 10 proved to be a challenge.
"Since Dustin's death we've been trying to get his dog, Lex, from the Marine Corps, and needless to say we've had some difficulty there," said Lee, a Mississippi Highway Patrol officer. "This thing went from colonels to generals all the way up to the commandant of the Marine Corps, and it almost went to the secretary of defense."
One issue was making sure the dog was not "overly aggressive." His behavior with the Lee youngsters -- Lex played tug of war with 13-year-old Camryn at his brother's funeral -- seemed to assure that wouldn't be a problem. Marine officials also said the request had to go through the Air Force, which is the approving authority for all military dogs.
Finally, on December 13, the Marines agreed to let Lex go live with Lee's family. It was the first time the Marines have released a dog before its retirement to a former handler's family. Watch the Marine's father describe what it took to adopt Lex »
"Lex has had two tours in Iraq," Jerome Lee said. "He's been through a lot, and we just want to get Lex home to our family and let him have a happy life."
Well before joining the Marines, Dustin Lee was known for his devotion to his country. A member of Quitman High School's cross-country track team, Lee and three teammates participated in the Americans United: Flag Across America Run after the September 11, 2001, attacks.
It was no surprise when the young man joined the Marines out of high school in 2004, nor when he went to Albany to train military police dogs. He reportedly was inspired by his mother's work with search and rescue team dogs when he was a boy.
An animal lover who also rode horses, the boy played hide-and-seek with his mother's dog, Jerome Lee said.
"He would let the dog get a sniff of his clothing and then go hide to see if the dog could find him," the elder Lee said. Watch as the Lee family describes bond between Marine and Lex »
At the logistics base in Albany, Lee said, he "worked with all the dogs and became the kennel master."
The Marine and Lex had been stationed in Falluja for nearly five months before the fatal attack. When the Marine's body was returned to Quitman in March, hundreds lined the streets waving American flags to say a tearful goodbye. And Lex was there.
In Albany on Thursday, kennel master Mike Reynolds led Lex through his paces for the last time in his military career. But it's time for the old pro to learn some new tricks in civilian life.
Jerome Lee said he hopes Lex's presence will make his other two children feel closer to their missing older brother.
"There's always going to be that missing link with Dusty gone," he said. "But part of Dusty is here with Lex." E-mail to a friend
CNN's Mike Phelan contributed to this report.
All About Iraq War