Gillingham have converted centre-half Leon Legge's loan from Brentford into a permanent two-year deal.
The 27-year-old has been a fixture in the Gills back four since joining on a one-month loan on New Year's Day.
Legge made his debut in the 1-0 win at Southend United and has since helped the team to keep three clean sheets in his first five appearances.
Meanwhile, Brentford have extended the loan spell of versatile Wigan man Rob Kiernan until the end of the season.
The 22-year-old, who can operate in defence or midfield, has played eight times for the Bees.