The Brazilian racer beat frontrunner Alex Tagliani out of the final pit stop, took the lead, and held off Japan's Takuma Sato by less than a second for the checkered flag at the City Centre Airport.
Will Power, Castroneves' Penske teammate, was third, 5.4 seconds off the pace.
For Castroneves, it was a big weight off his shoulders in the Alberta capital.
He had finished second three times in the last four races in Edmonton. In 2010 he took the checkered flag only to be stripped of the win for blocking Power.
"It's my second win here — but today it counts," said the 37-year-old from Sao Paulo.
"Today was a great day, realizing finally we can say we've won here."
For two-thirds of the event, under sunny skies and hot temperatures, it was Tagliani's race to lose.
The driver from Lachenaie, Que., started fourth and drove past pole-sitter Dario Franchitti on the first lap to take the lead.
He held off Franchitti and Castroneves until the final stint, when he changed tires, got passed by Castroneves, and slid down the grid.
Tagliani, with Team Barracuda, said the tires weren't right.
"As soon as we started pushing, (the car) started sliding and that maybe was the difference," he said.
"We just have to keep doing what we're doing and it (the win) is coming."
Tagliani was fifth at the flag for his best finish of the season. He was seventh at Milwaukee.
The win was the second of 2012 for Castroneves and moved him past Power into second in the driver standings, behind Ryan Hunter-Reay.
Hunter-Reay won the pole for the race on Edmonton's 2.2-mile, 13-turn course, but started 11th for an unapproved engine change. He finished 7th.
The loss snapped his string of three consecutive wins.
The race was accident free, with no yellow or red flags or restarts, which bunch the cars together and give the backmarkers a chance to move up.
Hunter-Reay said that was the difference.
"The guys had a solid day today, but we just needed a yellow," he said.
"To take an engine penalty on a day like today — at a track with long straights — we expected yellows. Maybe lots of them, but we just didn't get 'em."
Power qualified seventh but started 17th on the grid for his own engine change. He, too, said the error-free race was surprising.
"We don't get it very often in IndyCar to be full green on tracks where you can pass," he said.
"I would have been much more happy if I could have at least caught up to these guys (Sato and Castroneves) and had a battle, but they were running fast.
"I could see them battling and I hoped they would come together," he laughed.
Sato recorded the best finish of his career, but said he was disappointed.
"The winning was just there, close by, but we tried. We challenged and we attacked," he said.
"It's OK, we'll take second place."
Canadian James Hinchcliffe was never a factor. The 25-year-old from Oakville, Ont., started ninth on the grid but quickly dropped to 13th after getting pushed wide on a turn. He ended up 12th.
"It was definitely a tough race for us. The car wasn’t quite handling the way we needed it to," said Hinchcliffe, with Andretti Autosport.
"I didn’t drive great at the start and made a few mistakes. I set us back at the beginning and we were playing catch-up after that."
Castroneves, a three-time winner of the Indy 500, is enjoying a strong season.
He has been in the top six in seven of the 11 races, won in St. Petersburg, and was on pole in Alabama.
Edmonton had been no end of frustration for him, boiling over in 2010, when he took the checkered flag but was penalized for blocking Power with two laps to go.
That blocking manoeuvre allowed Scott Dixon to move past Power into second place. When Castroneves' win was disqualified, Dixon was declared the race winner despite not running in the lead all day.
An irate Castroneves then had to be restrained from getting to race officials in their tower on the infield. Photos of the angry Brazilian were flashed around the world.
Castroneves said Sunday's win doesn't diminish the sting of 2010, but said, "We've got to turn the page.
"I'm never going to forget what happened, but certainly we've go to move on."