Sometimes you love a movie even as you realize it’s far from perfect.

That’s what I’m here to tell ya. I loved “Gifted” even though I realize it’s far from perfect.

Yes, the screenplay creates a Big Ongoing Courtroom Conflict that could have been more readily resolved a half-dozen other ways.

Yes, the tear-soaked drama often crosses the line into unabashed, old-timey movie sentimentality.

And yes, any film with a lovable, one-eyed cat named Fred that winds up on Death Row at one point isn’t exactly being subtle about grabbing for your heart.

I wasn’t much bothered by any of that, because I cared so much about the characters, and I wanted things to work out for them, and maybe you’ll feel the same way after you see “Gifted.” Go see “Gifted.”

Chris Evans is of course best known for playing Steve Rogers/Captain America and he’s quite capable in that role, but Evans has the opportunity to flex different sets of acting muscles as Frank Adler in “Gifted,” and the result is maybe the best work he’s ever done. (Evans also gets to flex his actual muscles, as the Florida coastal locale of the story and his job as a boat mechanic afford plenty of opportunity for that.)

Frank acts like a crabby old man in a young man’s shell as he keeps his head down and tries to keep his interactions with the outside world to a bare minimum, but we know from the get-go this guy’s heart is in the right place.

Frank has had custody of his 7-year-old niece Mary (McKenna Grace) ever since Mary’s mother committed suicide when the girl was an infant. Even with their modest circumstances and Frank’s make-it-up-as-you-go-along approach to guardianship, they seem to be doing just fine on their own — until the time comes for Mary to get on the school bus and start the first grade.

This is the thing about Mary. She’s a mathematical genius, a one in a billion prodigy. On the first day of class, it takes about five minutes for Mary’s teacher Bonnie (Jenny Slate) to realize this kid should NOT be wasting her time adding two plus two.

This sets in motion a chain of events that includes the school’s principal (Elizabeth Marvel) offering to place Mary in an ultra-expensive school for gifted children — and the arrival from Boston of Frank’s estranged mother Evelyn (Lindsay Duncan), a wealthy, domineering presence who would have to warm up to have ice water in her veins.

Evelyn, a onetime math prodigy herself who was obsessed with pushing her daughter to greatness, has learned of her granddaughter’s prowess, which suddenly makes the child interesting to Evelyn. She swoops into town, meets Mary for the first time, gives Mary an Apple Macbook loaded with math texts, and announces she will be taking custody of the child. See you in court, son!

The screenplay by Tom Flynn is filled with sharp dialogue and warm, funny vignettes, but also some pretty big leaps of credibility, especially in the increasingly escalating emotions of the courtroom battle. (Evelyn has a scene on the witness stand that’s the cold-hearted mother’s version of Jack Nicholson’s self-destructive diatribe in “A Few Good Men.” It’s an amazing piece of acting from Lindsay Duncan, but it’s so theatrical you’ll feel as if you just walked into a Broadway play.)

Octavia Spencer supplies heart and humor as Roberta, the property manager/next-door neighbor who is always using her master key to enter Frank’s place and meddle in his life. (Frank pretends to be annoyed by this, but he is eternally grateful to have Roberta in his life — and more important, in Mary’s life.) And Jenny Slate gives a wonderfully modulated, sympathetic performance as Bonnie the schoolteacher, who tells Frank there’s no way they get involved, ahem.

In a role that requires much math talk and even more serious emoting, McKenna Grace is an irresistible force. Evans and Grace are sensational in their scenes together, whether it’s low-key bantering about the nature of her morning breakfast to waterworks-inducing separations and reunions.

“Gifted” isn’t the best or most sophisticated or most original film of the year so far — but it just might be my favorite.

★★★★

Fox Searchlight presents a film directed by Marc Webb and written by Tom Flynn. Rated PG-13 (for thematic elements, language, and some suggestive material). Running time: 101 minutes. Opens Friday at local theaters.