The actor reveals how seeing police at work close up, in the south-east of Los Angeles while researching his new movie, left an indelible mark on him and his co-star Michael Pena

It was Jake Gyllenhaal's first day of work on End of Watch when the murder happened. He was incognito in the back of an LAPD patrol car, observing protocol on the midnight shift. An emergency call came through. A drugs bust had gone wrong. Theirs was the second squad to arrive. Gyllenhaal opened his door, and a man was shot dead in front of him. He had five more months of ride-alongs still to go.

"I have a whole slew of feelings about that," he says one autumn morning in Toronto, the day after the movie's premiere, "but it was definitely an awakening. Domestic violence, chasing stolen cars, family disputes … growing up where I did in Los Angeles, I didn't see anything of this kind of violence." His Bambi eyes balloon with feeling. "Nor this sort of culture. South-east LA is 95% amazing culture, fantastic food, and it was great to be immersed in that world."

Gyllenhaal has long been big with the outreach. On his 13th birthday, in lieu of a party, he performed a "barmitzvah-like act, without the typical trappings" volunteering at a local homeless shelter. His parents – director Stephen Gyllenhaal and screenwriter Naomi Foner – encouraged him to take regular summer jobs to grit up his minted beginnings. When he adopted a rescue puppy, he named it Atticus, after Finch.

Such determined humility could seem icky; up close, that doffed cap is easy to swallow. At a press conference, he bats off queries about his beardy appearance with: "I totally respect the question but it's very hard for me to talk about hair when I feel like the police officers I worked with have much more important things to talk about. I feel I'd be doing them a disservice." (In fact, it's in aid of a play.)

Later, I meet him and co-star Michael Peña, holed up in a hotel basement. Gyllenhaal politely asks if I'd mind them jogging round the room to try to stay sparky. Then he's concerned I might be cold. Would I like his blazer? I put it on and explain most of my clothes are being fumigated for bedbugs. He blanches only briefly. "Oh, awesome! Well, it was a nice jacket while I had it. And my skin was really nice." Peña cackles. "Yeah, dude, you'll be doing that play like this." He mimes itchy nipples. Gyllenhaal giggles. They stop jogging and laugh harder.

Seeing these two together – in sync, if not quite joined at the hip – is curious. For End of Watch's blue uniforms are a bit of a red herring: this is a cop flick miles more excited by homies than homicide. Those pre-production ride-alongs weren't just to see the grisly side of police work, but its camaraderie, too – the 12-hour shifts with your best bud, the moonlit heart-to-hearts, all that happy yakking.

Problem was, when Gyllenhaal and Peña met, they didn't click. "It's so weird hanging out with this guy knowing he's going to be like your brother from another mother," says Peña. "It puts a lot of pressure on you. David [Ayer, the director] didn't want us to be actors. He's like: 'You guys will die for each other.' I'm like: 'Oh, shit. How am I gonna do this?' We spent so much time together. We were always sparring. And when somebody punches you in the face you realise, like, I'm gonna fight! It wasn't like any Hollywood shit; it was really getting down and dirty."

In the end, it took five months of roughhouse research for them to bond. When Gyllenhaal would head home after the 4am ride-along shift finished, "it'd take me a couple of hours to get to sleep. You're not really involved. Which makes you feel weirdly even more alone. Which is where Michael and I could connect. We would see things happen and say: well, our job is to observe it and then, absurdly, to fake it. Mike and I will always be close because of that."

Peña pipes up. "It changes you a little bit when you see a woman who has been smashed in the face and bleeding, and she doesn't want to press charges against her husband. And there was this one incident – the crowd were around us and I just didn't know what was going to go off. That's the one time that we got along. I knew: OK, this movie can work. I knew Jake would stick up for me."

What's strangest here is that it must have been at least partly intentional. After all, Ayer went through an exhaustive casting process, and Gyllenhaal was already on board – an executive producer, as well as the lead. Such initial stickiness was forseeable. Both actors may be self-confessed "drama geeks", but while Gyllenhaal got his first driving lesson from Paul Newman, on a racetrack, Peña literally wrestled his way out of the Chicago ghetto (he was a semi-professional who tried out for WWE).

And it's these divisions that lend the film an interesting friction. "A lot of rehearsal was knowing each others back-story," says Peña. "I know his sister well and I met his mom – beautiful woman. So, in the car, I was talking to him." And while End of Watch has its own genre spin (the police are the good guys, not the dirty DIs of Harsh Times and Training Day), it is these scenes behind the wheel, before the film spins off into its plot proper, that mean End of Watch stands out so brightly in a lineup of cop movies.

It tackles ethnic difference head on, and with humour – the key promotional clip has the pair sat in the car, Gyllenhaal taking the piss out of the endless quinceañeras his partner must attend, Peña doing the same for a caucasian love of elaborate coffee. There are two trailers, one foregrounding Peña, partly in Spanish, the other playing it as a straight Gyllenhaal vehicle that progresses along well-trod tyre tracks ("They were the city's top guns …"). Their relationship, then, is a careful construct, deftly peddled – not just with punters, but the LAPD themselves.

Jake Gyllenhaal and Michael Peña in End of Watch. Photograph: Studio Canal

"It moves them," says Gyllenhaal, "because it shows so much of why they love the job – and that's the stuff in the car. My best friends in the world, we express our love for each other through a whole lot of shit-taking. Romance is important, but to have a friend you can use as a mirror, who can give you an objective response, that's what's really important." Agrees Ayer: "Cops really love taking the piss out of each other. I've shown the film to officers all over the county and they all say the same thing: finally somebody got it right."

Such close ties between film-makers and their subjects are rare. Ayer, an ex-Navy officer with a voice like a submarine and a build to match, has constructed a career with the police, even if it has been in fictionalising them rather than serving with them. Peña, meanwhile, is in awe of his real-life sibling, who works in a correctional facility in Chicago. For Gyllenhaal: "the film changed my life. I have three really close friends from the production process. The movie to me almost feels like an afterthought."

Such fraternity is also potentially concerning. End of Watch is a terrific film, and, to be fair, our heroes do happen upon some remarkably grisly finds on even the most innocuous housecall, but it will also function as a persuasive recruitment video. Did Gyllenhaal ever worry being embedded with the LAPD might just mean they were in bed with them?

"Yes and no. I don't think you can approach any piece of art with boundaries or rules. I think respect is a very important thing but I also think what we discover along the way is really important. I think what we were trying to stay true to was the authenticity of what we saw, not the romantic version."

Ayer, too, slightly sidesteps the question, though he's quick to assure that the LAPD had no editorial veto. So why is the force so well-represented on film? "It's such a unique department. When they get involved in scandal it's in a big way. I think it's the visually coolest agency. They have that classic look – they look like the police. Their demeanour and style; the famous command presence of their officers. Everyone's always struck by it. Those guys are intense! They're so confident. They're like military." He sighs with appreciation and swigs a Coke. "We Americans greet our servicemen as they come back from overseas and we shake their hands and thank them. Not the case with cops who go into harm's way."

Why? He pauses. "I think people are intimated by the police. At the end of the day, it's a secret society. It's not a place where regular citizens get to see behind the facade." He doesn't think there's any other reason people feel wary? "Absolutely I do believe there is a bit of psychological protection. They can read my mind; they can see my sins. I have pot in my car. I took a Zanax. All our petty faults are writ large."

Once you speak longer with Ayer, seeds of scepticism seem to sprout. He wouldn't mind branching out to make a romcom, he says. There are all sorts of limits to the LAPD. "Without them, society would be a fucking disaster. With them they can sorta hold the line clean of the mess. But it's just triage." Yes, he says, policing is inherently ballsy; and it's true that the women in the force as well as the film must mold themselves to be more macho. "It's aggressive. Are you willing to kill somebody? If you answer 'no' then don't be a cop."

The actors, though, aren't so sure. They stand up tall in that hotel basement, and they ponder earnestly, eager not to let their colleagues on the squad down. "It's about putting on an act," says Gyllenhaal. "Whatever your sex. Cops go into a black neighbourhood and respond differently than if they're in a Hispanic neighbourhood. They adapt in a way I've rarely seen in any other profession besides acting. That's maybe the only similarity between our jobs – the ability to observe human behaviour and imitate it. Theirs is for survival and ours is absurd in comparison. But maybe 'brotherhood' is misleading. It's a big family. I know that does sound cliched but when you get to its authenticity, it's anything but."

Time's up. I hand back Gyllenhaal's blazer and he slips it on, faint fear creasing the grin. A week or so later I read the first reviews of his play, just opened on Broadway. None seem to mention any unexplained scratching. They all talk about the beard, though.

• End of Watch is out on 23 November

More on Jake Gyllenhaal and End of Watch

• Jake Gyllenhaal: 'I'm moved by folk you might struggle to love at first'

• End of Watch - video review