The fake lawyer who walked into Manhattan courtrooms last year pretending he was a real attorney was sentenced yesterday to up to three years in prison for filing a false instrument and other charges — and then took the time to thank the man who prosecuted him.

Terence Kindlon, 42, looked at prosecutor Daniel Cort and said, sincerely, “Thanks a lot,” as he was led out. He also thanked the judge and his attorney.

Kindlon — the heroin-addict son of a prominent Albany lawyer — had walked into a Manhattan courtroom three times at the end of last year impersonating attorney David O’Brien, despite having no law license.