Boss lands former Boro midfielder
Bailey, who cost Boro £1.4m when he joined them from Charlton three years ago, was a free agent after his contract at the Riverside expired this summer.
The London born player is pleased to be returning to the capital, but more than that is ambitious for success at The Den.
He said: "I believe that with the new players coming in added to those who did well in the early part of last season, we can be a force in the Championship.
I'm looking forward to a new start at Millwall, and ideally scoring more goals from midfield than I had the opportunity to do at Boro.
The fans at The Den are very passionate about their football, and I hope they will see in me a player who gives 100% to the cause every time I pull on the shirt."
Bailey becomes The Lions' sixth close season signing, following the arrivals of Stephen Bywater, Jermaine Easter, Lee Martin, Steve Morison and Richard Chaplow.
He will not be included in the squad at Gillingham, but is expected to be in action next weekend in Paul Robinson's testimonial.
Lions Player subscribers will be able to view an exclusive interview with Nicky Bailey from lunchtime on Saturday.