If formally offered the position, retired Gen. John Kelly would be the third general tapped by Donald Trump. | Getty Gen. John Kelly seen as leading contender for DHS

Retired Marine General John Kelly has emerged as the top contender to lead President-elect Donald Trump’s Department of Homeland Security, according to three sources close to the transition.

Kelly, 66, whose military career spanned more than four decades, retired earlier this year as the chief of U.S. Southern Command. In that post, where he oversaw military operations in most of Central and South America, he publicly clashed with the Obama administration on its plans – which were never executed – to close Guantanamo Bay and dismissed as “foolishness” concerns that the military’s treatment of detainees at the facility had cost the U.S. the moral high ground in the War on Terror.

At the Department of Homeland Security, a massive bureaucracy created in the wake of the Sept. 11 terrorist attacks, Kelly would become a key player in Trump's plans to secure the border and crack down on illegal immigration. The president-elect campaigned on a plan to build a wall along the U.S.-Mexico border and to swiftly deport undocumented immigrants guilty of crimes.

His addition to the Trump administration would likely have implications on candidates for remaining cabinet posts. If formally offered the position, Kelly would be the third general tapped by the president-elect, in addition to Lt. Gen. Michael Flynn, who will serve as Trump’s national security adviser, and retired Gen. James Mattis, who Trump said Thursday he intended to nominate as his Defense Secretary. Concerns about the number of military officials in Trump’s cabinet may harm the prospects of another military man, retired Gen. David Petraeus, whom Trump is considering for secretary of state.

A Trump transition spokesman did not respond to a request for comment.

During the campaign between Trump and Hillary Clinton, Kelly said he'd be willing to serve in either administration. But unlike other notable high-ranking former military officials like Flynn and Gen. John Allen, the retired four star general never endorsed a candidate. Whoever won, Kelly said, shouldn't doubt they're “getting anything but the absolute best military advice, completely devoid of politics.”

“It adds to this mistrust issue...if suddenly a guy retires and says, ‘I think this administration is doing all the wrong things for all the wrong reasons,’” Kelly told Foreign Policy about endorsing a candidate.

Kelly’s son 2nd Lt. Robert M. Kelly died in 2010 when he stepped on a landmine on a tour of duty in southern Afghanistan, and Kelly remains one of the most senior U.S. military officers to lose a son or daughter in Iraq or Afghanistan. He has also opposed the Obama administration’s decision to open combat roles to women.

Kelly enlisted in the Marine Corps in 1970 and was discharged two years later. He was then commissioned as an officer in 1976. He served multiple tours of duty in Iraq and was a military aide to both Defense Secretaries Robert Gates and Leon Panetta.

Jennifer Scholtes contributed to this report.