League One side Gillingham have signed Queens Park Rangers defender Max Ehmer.
The 23-year-old German, who had a loan spell with the Gills last season, has agreed a three-year contract.
"Max showed us the qualities he has as a player and what he is as an individual," Gills boss Justin Edinburgh told BBC Radio Kent.
"He is one we wanted to secure and it has been a bit more difficult than we thought. Credit to the chairman, who has worked tirelessly on this one."
Ehmer joined Gillingham on loan in November, and went on to score one goal in 29 appearances for the Kent club.
Edinburgh believes the centre-back's successful stint at Priestfield Stadium last season helped them secure a permanent move.
"It is the advantage of when you get a loan player and they settle at the club," he said. "You work with them and they know what they are about, so it does give you a head start sometimes."
Ehmer has joined on a free transfer and is Gillingham's fifth signing of the summer.
Edinburgh expects "another three or four" arrivals before the end of the transfer window, adding: "We are in dialogue with another couple of players and we have loan movements we are working on.
"I'm hoping by the time we are back from France [on 19 July] we will more or less have the squad in place. We need another central defender and a central midfielder and then we'll see where we go from there."
Find all the latest football transfers on our dedicated page.