JavaScript (ES7ES6), 113104 bytes
Saved 9 bytes by refactoring in a way similar to what xnor did
Expects (N,x1,y1,x2,y2).
(N,x,y,X,Y)=>Math.min(...[a=x-X,a-N(g=q=>[x,c=X+x+~Nx+q,c-N,c,a+N]-x].map((v,i)=>v*v+[b=y=>Math.hypot(X-Y,d=Y+y+~Nv,bY-N[y,N-d,b+Ny,d][i]**2y+q][i]))**)(N++),.5..g(1-N))