What a difference a strong “Dancing with the Stars” lead-in makes.

A growth story for much of this season, “Castle” has benefited big time over the last two weeks, thanks to a surging “Dancing.” Now, ABC has given an early third season pickup to the drama.

Pickup comes after Monday night’s episode — the second half of a two-parter — landed the No. 1 slot at 10 p.m., and also posted its best ratings ever among adults 18-49 (3.7/10) and total viewers (14.5 million).

According to ABC, “Castle” even gave ABC its largest Monday 10 p.m. audience for a regular scripted series since 1996 (!) and its best adults 18-49 mark there since 2001.

Pickup is for a full 22-episode third season.

“Castle,” which launched last midseason, stars Nathan Fillion as a novelist who winds up helping an NYPD detective (Stana Katic) solve crimes. Susan Sullivan, Molly Quinn, Ruben Santiago-Hudson, Tamala Jones, Jon Huertas and Seamus Dever also star.

ABC Studios is behind “Castle,” which comes from exec producers Andrew Marlowe, Rob Bowman, René Echevarria, Laurie Zaks and Armyan Bernstein.